2010年10月25日 星期一

manuplate bash parameter

1:redefine IFS
2:rewind parameters

alias will not work in a shell script. using function is an alternate solution to redefine the command which you want to run.

ex:
Parent Process
#!/bin/sh
. /path_of_script/Child_Script
echo "This is a test mail"|mail -s "Test Mail" email@domain

Child Process
#!/bin/sh
function mail(){
myInput=""
for input in "$@"
do
input="${input/ /_}"
if [ "${input:0:1}" == "-" ] && [ "${input}" != "" ] ; then
myInput="${myInput}${input} "
else
myInput="${myInput}${input} "
fi
done

myInput="/usr/bin/mutt -F /tmp/demo/SignOffAdmin ${myInput}"
$myInput
}

please note double quote for $@ is a must
refer to http://www.ibm.com/developerworks/library/l-bash-parameters.html