I wrote a bash script which takes parameters by name and read its value in key value pairs. Below is an example of how I run my script.
sh test.sh param1='a' param2='b'
I then refer the input arguments like $param1 and $param2 inside my script. Below is the script I wrote to do this.
for item in $@; do
case $item in
(*=*) eval $item;;
esac
done
But when there is space in the value of the argument, it takes only the part before the space.
param3='select * from'
would only assign 'select' to param3 and not the whole string. How can I achieve this? Any help would be much appreciated.
EDIT :
After Inian's answer
for item in $@; do
case "$item" in
(*=*) eval "$item";;
esac
done
param1='a' param2='b' sh test.shinstead? This will makeecho "$param1"available immediately without parsing