ksh

Return value from a Java code

心不动则不痛 提交于 2019-12-21 06:58:53
问题 There is a Java class which creates a POST request and sends it to a servlet. The main method of the class file (test) looks something like this: public static void main(String[] args) throws IOException { // Code logic goes here... // No return Statement } This is called from a KornShell (ksh) script something like this: retcode=`$CLK_JAVA_PATH -cp $CLASSPATH test ${PASSWORD} ${HOSTNAME} ${TOOLSET}` if [ $? != "0" ];then echo "ERROR: echo "${retcode}" else echo "${SCRIPT} Success" fi retcode

Single command to create a file and set its permission

こ雲淡風輕ζ 提交于 2019-12-20 09:12:58
问题 I am using the following 2 commands to create a 0B file and set its extn to 644 touch filename.ext chmod 777 filename.txt My question is that whether there is any single command in unix (korn shell) that will do the two things together that is to say create a 0B fil with desired permission? 回答1: install -m 777 /dev/null filename.txt 回答2: For bash , simply use chmod with file redirection and history expansion: chmod 777 filename.txt>>!#:2 For ksh and zsh you have to drop the history expansion

Running a Block of Shell Script remotely using SSH

巧了我就是萌 提交于 2019-12-20 05:37:29
问题 I am try to execute a block of commands on a different server using a shell script Can anyone please help me on this while [ $RecordCount -gt 0 ] do expXXXXX=`sed -n ${RecordCount}p ${GUID_DLT_EXPR_FILE} | cut -d "|" -f1` exprXXXXXn_id=`sed -n ${RecordCount}p ${GUID_DLT_EXPR_FILE} | cut -d'|' -f2` run_dt=`sed -n ${RecordCount}p ${GUID_DLT_EXPR_FILE} | cut -d'|' -f3` #START OF THE BLOCK - IN SERVER 2 if [ -d "/sas/ADH/exXd_$expXXXXX" ]; then if [ -d "/sas/ADH/exXd_$expXXXXX/version_$exprXXXXXn

pass wildcard to cut command in shell script and store it in a variable

纵然是瞬间 提交于 2019-12-20 05:23:18
问题 I am new to shell, I have a case where I am trying to evaluate a particular column unique values to check if they are valid in a shell script which will be invoked later. From my searches I think cut along with sort & unique is good to do it So my attempt is file=/filepath/*vendor.csv file_categories = `cut -d, -f1 $file |sort |unique` $file should hold file which has vendor in its filename but even after using command substitution (`) the $file is not getting replaced with the correct

Unix parsing pipe delimited format string in ksh

此生再无相见时 提交于 2019-12-20 03:17:27
问题 I am writing ksh script to parse a pipe delimited string export dummy="abc" echo "123|456|789" | awk '{split($0,output,"|"); print output[3] output[2] output[1]}' above code seems to work , but I am not able to assign value of output[3] to dummy. Is there a way to do such parsing, but I want to assign the parsing result in a variable within ksh space i.e. dummy (in above sample)? 回答1: The shell can do it: line="123|456|789" IFS='|' read a b c <<END $line END echo $c # => 789 回答2: You can't

Where does the recursive variable expansion in bash/shell numeric contexts come from?

只谈情不闲聊 提交于 2019-12-20 01:08:51
问题 The POSIX spec states with regard to Arithmetic Expansion that [i]f the shell variable x contains a value that forms a valid integer constant, optionally including a leading plus or minus sign, then the arithmetic expansions "$((x))" and "$(($x))" shall return the same value. Which is a reasonable shortcut and cleans up complicated expressions rather nicely. bash (versions 3.2.25(1)-release from CentOS 5 and 4.3.33(1)-release from debian unstable) as well as ksh ( Version AJM 93t+ 2010-06-21

KornShell Sort Array of Integers

拈花ヽ惹草 提交于 2019-12-19 10:57:52
问题 Is there a command in KornShell (ksh) scripting to sort an array of integers? In this specific case, I am interested in simplicity over efficiency. For example if the variable $UNSORTED_ARR contained values "100911, 111228, 090822" and I wanted to store the result in $SORTED_ARR 回答1: Is it actually an indexed array or a list in a string? Array: UNSORTED_ARR=(100911 111228 090822) SORTED_ARR=($(printf "%s\n" ${UNSORTED_ARR[@]} | sort -n)) String: UNSORTED_ARR="100911, 111228, 090822" SORTED

How do i replace [] brackets using SED

微笑、不失礼 提交于 2019-12-18 18:57:09
问题 I have a string that i am want to remove punctuation from. I started with sed 's/[[:punct:]]/ /g' But i had problems on HP-UX not liking that all the time, and some times i would get a 0 and anything after a $ in my string would dissappear. So i decided to try to do it manually. I have the following code which works on all my punctuation that I am interested in, except I cannot seem to add square brackets "[]" to my sed with anything else, otherwise it does not replace anything, and i dont

Iterating through a range of ints in ksh?

纵饮孤独 提交于 2019-12-18 12:49:12
问题 How can I iterate through a simple range of ints using a for loop in ksh? For example, my script currently does this... for i in 1 2 3 4 5 6 7 do #stuff done ...but I'd like to extend the range way above 7. Is there a better syntax? 回答1: Curly brackets? for i in {1..7} do #stuff done 回答2: While loop? while [[ $i -lt 1000 ]] ; do # stuff (( i += 1 )) done 回答3: ksh93 , Bash and zsh all understand C-like for loop syntax: for ((i=1; i<=9; i++)) do echo $i done Unfortunately, while ksh and zsh

How do you use ssh in a shell script?

旧街凉风 提交于 2019-12-18 12:17:24
问题 When I try to use an ssh command in a shell script, the command just sits there. Do you have an example of how to use ssh in a shell script? 回答1: Depends on what you want to do, and how you use it. If you just want to execute a command remotely and safely on another machine, just use ssh user@host command for example ssh user@host ls In order to do this safely you need to either ask the user for the password during runtime, or set up keys on the remote host. 回答2: First, you need to make sure