ksh

Using tail in a subshell in conjunction with while/break does not exit the loop

不打扰是莪最后的温柔 提交于 2019-12-24 11:05:54
问题 I have been facing a very peculiar issue with shell scripts. Here is the scenario Script1 (spawns in background)--> Script2 Script2 has the following code function check_log() { logfile=$1 tail -5f ${logfile} | while read line do echo $line if echo $line|grep "${triggerword}";then echo "Logout completion detected" start_leaks_detection triggerwordfound=true echo "Leaks detection complete" fi if $triggerwordfound;then echo "Trigger word found and processing complete.Exiting" break fi done echo

ksh get exit status in assignment

回眸只為那壹抹淺笑 提交于 2019-12-24 03:37:49
问题 I need to know the exit status of command that do assignment. export VALUE=`My_Get_Value 10` I need to know the exit status of My_Get_Value script. In the $? I have the status of assignment itself. I need it in KSH v93 回答1: export VALUE=$(My_Get_Value 10) is not an assignment statement; it is a call to the export command, which takes arguments that look like assignment statements. The easiest fix is to separate the assignment from the call to export . VALUE=$(My_Get_Value 10) mgv_exit=$?

How do I do an exact word match on a variable in ksh?

拈花ヽ惹草 提交于 2019-12-23 23:03:09
问题 I used the following syntax as part of a ksh script to verify if the word Validation exists in LINE_FROM_FILE . [[ "${LINE_FROM_FILE##*Validation}" != "${LINE_FROM_FILE}" ]] && print "match Validation" The problem of this syntax is that it is also matching words like Valid or ValidationVALID etc. and my goal is to exactly match the word Validation in the variable $LINE_FROM_FILE . I ask if it is also possible to use Perl syntax in my script to exactly match the word Validation , for example:

KornShell Printf - Padding a string

妖精的绣舞 提交于 2019-12-23 19:32:21
问题 I'm attempting to write a KornShell (ksh) function that uses printf to pad a string to a certain width. Examples: Call padSpaces Hello 10 Output 'Hello ' I currently have: padSpaces(){ WIDTH=$2 FORMAT="%-${WIDTH}.${WIDTH}s" printf $FORMAT $1 } Edit: This seems to be working, in and of itself, but when I assign this in the script it seems to lose all but the first space. TEXT=`padSpaces "TEST" 10` TEXT="${TEXT}A" echo ${TEXT} Output: TEST A I'm also open to suggestions that don't use printf.

Shell script user prompt/input

﹥>﹥吖頭↗ 提交于 2019-12-23 08:35:55
问题 This is a crude korn shell script that someone else wrote. I don't know much about using shell syntax and I'm not even sure if this is possible. Is there any way for me to run this file and be prompted for the date so that I don't have to manually go into the script and change it each time? For example, I want to replace the "1/12/09" with a variable that is taken from a user prompt. #!/bin/ksh ./clear_old ./rooms_xls.pl 1/12/09 cd doors ./doors_xls.pl 1/12/09 回答1: If you want to be prompted

Unix shell - read array content in a for loop

旧城冷巷雨未停 提交于 2019-12-23 05:43:31
问题 this is my array: orlist="" orlist="T_TAB1 \n" orlist=$orlist"T_TAB2 \n" orlist=$orlist"T_TAB3 \n" orlist=$orlist"T_TAB4 \n" echo $orlist arrIdx=0 OLD_IFS=$IFS; IFS="\n" for IndixList in ${orlist[@]}; do echo $IndxList MYDIR[${arraryIndix}]=$IndixList (( arraryIndix = $arraryIndix+ 1 )) done IFS=$OLD_IFS i have to do a SELECT in a oracle db inside a for loop so i have to read the $orlist tab by tab. I've tried this but doesn't work it takes the whole array not tab by tab: for arraryIndix in $

which is the fastest way to print in awk

早过忘川 提交于 2019-12-23 05:29:22
问题 I am trying to make some measurements, and i would like to know what is the fastest way to print something through nawk . at the moment i use printf ARR[2] " "; , but it seems to take more time than normal to print. Info: I am printing around 500 numbers and adding the space in the printf so that not everything would be stucked together in the print out. Also i am running the script on ksh, in unix oracle solaris. Like this, it needs around 14 seconds to print everything, is there any faster

Is there any way to prevent find from digging down recursively into subdirectories?

寵の児 提交于 2019-12-22 10:33:22
问题 When I do: $ find / It searches the entire system. How do I prevent that? (This question comes from an "answer" to another question.) 回答1: G'day, Just wanted to expand on the suggestion from Jon to use -prune. It isn't the easiest of find options to use, for example to just search in the current directory the find command looks like: find . \( -type d ! -name . -prune \) -o \( <the bit you want to look for> \) this will stop find from descending into sub-directories within this directory.

How can I program ksh93 to use bash autocompletion?

帅比萌擦擦* 提交于 2019-12-22 09:59:37
问题 In a comment in response to a shell question, user tinkertim said that it was easy to hack ksh to use the bash autocompletion library. I would like nothing better than to use bash autocompletion with AT&T ksh93 . How can this be done? ksh93 has a new release several times a year, so I am looking for a solution that does not involve modifying the source code. ksh93 can link new C modules dynamically and also is highly programmable (I run a ksh function at every keystroke), so modifying the

changing to parent directory in unix

大憨熊 提交于 2019-12-21 07:24:16
问题 in general we use cd .. for going to the parent directory cd ../../ to go to the parents parent directory. and cd ../../../../../ for 5th parent directory. is there any simplified way of doing this? shell i am using is ksh. 回答1: This function is for Bash, but something similar could be done for others (this may work as-is in ksh and zsh): cdn () { pushd .; for ((i=1; i<=$1; i++)); do cd ..; done; pwd; } Example usage: /some/dirs/and/subdirs$ cdn 3 /some/dirs/and/subdirs /some/dirs/and/subdirs