I know there are other ways of accomplishing the below task, but the purpose of this thread is to understand the below code.
I wanted to use xargs with user defined function in korn shell. Am aware, that I could write custom function into a script and place it in FPATH and then call it in xargs, but I wanted to have it all in the same shell script. Bash isnt an option for me at the moment. After 2-3 days of searching, I found the solution which works, but am unable to understand a part of it..
cat ordernum.txt | xargs -P 25 -n 1 ksh -c '
function fun {
do some processing
}
shift "$1"
fun "$@"' 2 1
Can someone help me with the last two lines of the code.
shift moves the parameters so that $2 is now $1,etc.
$@
Inside double quote marks (" "), parameter and command substitution occur and \ quotes the characters \, `, ", and $. A $ in front of a double quoted string will be ignored in the "C" or "POSIX" locale, and may cause the string to be replaced by a locale specific string otherwise. The meaning of $* and $@ is identical when not quoted or when used as a variable assignment value or as a file name. However, when used as a command argument, "$*" is equivalent to "$1d $2d . . .", where d is the first character of the IFS variable, whereas "$@" is equivalent to "$1" "$2" . . . . Inside grave quote marks (` `), \ quotes the characters \, `, and $. If the grave quotes occur within double quotes, then \ also quotes the character ".