Tag Info

New answers tagged

0

Try awk -v pattern="bar3" 'match($0, pattern){ beg = index( $0, ">") content = gensub(/<.*$/, "", "", gensub(/^[^>]+>/, "", "", $0)) beg_str = index( content, pattern) if (match (content, pattern)) { print substr($0, 0, beg) substr(content, 0, beg_str - 1) "<fontstyle=BACKGROUND-COLOR:red>" substr(content, beg_str, ...


2

The following works for me in mksh: $ echo $KSH_VERSION @(#)MIRBSD KSH R50 2014/10/07 $ x="Red,Yellow is a color,Blue" $ oIFS=$IFS $ IFS=, $ y=($x) $ IFS=$oIFS $ echo ${y[1]} Yellow is a color I believe it should work the same way in all versions of ksh.


1

Variables are interpreted in a here doc (<<...), so you need to escape the ones you don't want evaluated yet. su - db2prd<<EOF PARMDATE=1111111 echo parmdate echo \$PARMDATE EOF Or better, quote the delimiter (here EOF) to tell your shell not to perform expansions inside the here-document: su - db2prd<<'EOF' PARMDATE=1111111 echo ...


0

You're almost there! Just tell date to use a format on which computation is easy. lastUpdate=$(date -r myLogFile.log +%s) now=$(date +%s) file_age=$((now - lastUpdate))


2

lastUpdate="$(stat -c %Y myLogFile.log)" now="$(date +%s)" let diff="${now}-${lastUpdate}"


0

compare the two outputs to get the number of seconds between now and the modified date stat -c %Y file vs date +%s


2

I can't say exactly for ksh, but from the experience with other shells - they cache current session history and push it to the file on exit. So history file removal affects on a new session, not the currently opened.


0

What I found was that on older HP-UX machines (parisc 11.11), I had to use [^a]* But, on newer machines (parisc 11.31 and newer) it works with !(a*) This is what I ended up with. And it works: if [[ ${S_MACH} = "phd026a" || ${S_MACH} = "tht030a" ]] then scp -p -r ${S_MACH}:${S_DIR}/bin/[^a^b^c^p]* ${D_DIR}/bin/. else ...


0

I don't know if it is clear but you may be interrupting the loop when you are using break and exit set -A arrs a b c d num=`expr ${#arrs[*]} - 1` for x in `seq 0 $num` do var1=`some command here` var2=`some command here` var3=`some command here` if [[ "$var1" == "$var2" && "$var3" == "0" ]] then #do something here ...


1

You added break in the yes statement, so it is exiting the for-loop and therefore not finish testing the rest of the array. Just remove break from the 'yes' case statement. I tested with some modifications to your code, and got what I believe are your expected results: #!/bin/sh arrs=(a b c d) num=`expr ${#arrs[*]} - 1` for x in `seq 0 $num` do ...


1

You can make ksh load another file at start by setting ENV in $HOME/.profile point to a readable file. ksh will run that file as a script. Example: $ echo 'ENV=$HOME/custom_kshrc' >> ~/.profile $ echo 'export ENV' >> ~/.profile $ . ~/.profile $ printf 'AAA=QQQ\nexport AAA\necho Done\n' > custom_kshrc $ ksh Done % env | grep AAA AAA=QQQ


3

Tar in AIX by default does not support compression. You will need to incorporate with gzip command to have it tar and compress at the same time. $ tar cvf test.tar test # pure tar only $ tar cvf - test | gzip > test.tar.gz # tar and compress together To uncompress and untar: $ gunzip -c test.tar.gz | tar tvf - # ...


5

tar cjf <your-name-in-specific-path> <your-directory-path> c: Create j: Use bzip2 for compression f: Save it to given file name NOTE: If your tar version doesn't have these options you can follow the below instruction: tar cf <your-name-in-specific-path> <your-directory-path> gzip ...


3

A directory cannot be compressed, because a directory is not a plain file. It is a pointer to a container of a set of files. You can tar a directory and its contents into a single file and compress that file. Or you can cd into the directory and compress each individual file.


1

The man page of your shell will usually help. Lets take your first example. if [ $? -ne 0 ]; then On my system man ksh says: if list ;then list [ ;elif list ;then list ] ... [ ;else list ] ;fi The list following if is executed and, if it returns a zero exit sta‐ tus, the list following the first then is executed. Otherwise, ...


1

You'd get that error message if you had turned the -u option either by invoking ksh as ksh -u or ksh -o nounset or by running set -u or set -o nounset. touch $var1 $var2 $var3 is wrong anyway unless those variables are meant to contain lists of file patterns. It should have been: touch -- "$var1" "$var2" "$var3" Now, if you want to allow one of them to ...


0

I doubt if you can do it just in a line, you can try something like this validate_touch() { for value in "$@" do if [ ! -z "$value" ]; then touch $value;fi done } validate_touch new


3

sed "s/.\{$(($RANDOM%${#a}))\}/&$b/" <<< $a where: $RANDOM pseudo-random value from 0 to $RAND_MAX (usually 0x7fff == 32767) ${#a} length of target string $((...%...)) outputs the resedue from dividing .{n} match first n characters of input string s/.../&$b/ substitutes pattern match by themselves + $b


0

an attempt in awk: awk "{srand(); i=int(rand()*length(\$0)); print substr(\$0,0,i)\"${b}\"substr(\$0,i)}" <<< $a


1

set -- while [ "$(($#>5))" -eq "-${#status}" ] do "test"; ${status:+":"} sleep 3 set '' "$@" done If you test by complement you can often do a lot more with one test.


0

My Accepted answer on SO: If you only want to see a failure when all tests fail? When you can skip the other tests when one test succeeds, you can use test1 || sleep 3 && \ test2 || sleep 3 && \ test3 || sleep 3 && \ test4 || sleep 3 && \ test5 || exit 1


1

Simply add a minus sign: TZ=ZZZ0 touch -t "$(TZ=ZZZ-0:30 date +%Y%m%d%H%M.%S)" $HOME/reference Or invert your timezone trick: TZ=ZZZ0:30 touch -t "$(TZ=ZZZ0 date +%Y%m%d%H%M.%S)" $HOME/reference If you need to go beyond the range of timezone offsets, standard shell utilities notoriously lack a way to manipulate date. Various people have done the job of ...


0

Use that command: touch -t "$( printf '%(%Y%m%d%H%M.%S)T\n' 'now +30 minutes' )" file With -t of touch you can specify a date. And wih ksh's printf it is also possible to format a date. with the %(date-format)T, see the manual page of ksh.


0

You can let the globs resolve themselves. As far as I'm aware, this strategy should be very shell portable for every case except one in which you have read permissions for dir/ but only search permissions for dir/../. This is because read and search permissions are required to resolve a glob, but only search permissions to show up a match. set di[r]/* ...


2

Here's a POSIX-compliant way of testing whether dir is empty using only built-in shell constructs. The set command sets the positional arguments to dot files (including the always-existing . and ..) followed by non-dot files. If the directory is empty then the .* glob only matches . and .., and the * glob matches nothing so remains unexpanded. set dir/.* ...


0

I know of no direct way, and it also depends on whether you want also dot-files to be considered. This (or a variant thereof) may do what you want... set directory/* [[ -f $1 ]] || print empty


0

In any shell [ "$(find path_to_dir -mindepth 1)" ] || echo EMPTY


2

If your variable is exported (bash: by the export command or by default because of set -a) then a called shell gets it in its environment like any other process would.


3

If you don't have ksh93 available, you can do it in standard ksh like this: function capitalize { typeset -u first first=${1%"${1#?}"} print "${first}${1#?}" } ${1#?} strips all characters matching "?" from the beginning of the first arg. i.e. strips off the first character ${var%pattern} strips off pattern from the end of var. If we use the ...


2

Use read x='';while [[ "$x" != "A" ]]; do read -n1 x; done read -n 1 is to read 1 character. This should work in bash but you can check if it works in ksh


2

This is used to get the filename from the full path. This is similar to using the basename command. Example: filename="/tmp/test.txt" echo "$filename" "${filename##*/}" /tmp/test.txt test.txt basename "$filename" test.txt``


0

This seems to work for me on ksh PS1=$'$HOSTNAME $PWD\n$ ' The output is like below myhost /user/varghese $


1

Try to pipe otput via sed 's/\S\+ \(= \|in (\)/\1/g'


0

First of all, for debugging purposes, redirect the stderr to some file as well. This way you'll know what goes wrong. 15 * * * * /bin/ksh /wls_domains/resMGT/logs/bea/wlr3queuetransaction.sh 2>LOG_FILE > /wls_domains/resMGT/logs/bea/data/script.log Next if it isn't a file location issue, take a look at this question, as it is very similar: how to set ...


1

Your script does cat wlr3queue.txt etc.... where are those files to be found? When you're trying by hand you're running ./wlr3queuetransaction.sh but from cron you're calling with the complete pathname. Cron will run your command from the crontab's owner's home directory; presumably the files you're accessing in your script aren't in that home directory. ...



Top 50 recent answers are included