learning shell args handing key=value example (2)
Shell args handing key=value example
【Purpose】
Learning how to handing ker=value args
【Eevironment】
Ubuntu 16.04 bash env
【Procdeure】
Source code:
1 # Script parameters handling get left parameters and right value 2 3 for i in "$@"; do 4 if [[ $i == *=* ]]; then 5 parameter=${i%%=*} 6 value=${i##*=} 7 display_alert "Command line: setting $parameter to" "${value:-(empty)}" "info" 8 eval $parameter=$value 9 fi 10 done
Test method:
vmuser@vmuser-virtual-machine:~/panzidong/shell$ ./test-args-handing.sh test1=111 test2=2222 test3=
Command line: setting test1 to 111
Command line: setting test2 to 2222
Command line: setting test3 to (empty)