I’m trying the whole day to find a good way for parsing some strings with a shell script. the strings are used as calling parameter for some applications.
they looks like:
parsingParams -c "id=uid5 prog=/opt/bin/example arg="-D -t5 >/dev/null 1>&2" info='fdhff fd'" start
I’m only allowed to use shell-script. I tried to use some sed and cut commands but nothing works fine.
My tries are like:
prog=$(echo $@ | cut -d= -f3 | sed 's|s.*$||')
that return the correct value of prog but for the value of arg I couldn’t find a good way to get it. the info parameter is optional also it may be left. may any one have a good idea that can solve this problem? many thanks in advance
Advertisement
Answer
eval
$ eval "id=uid5 prog=/opt/bin/example arg="-D -t5 >/dev/null 1>&2" info='fdhff fd'" $ echo $id uid5 $ echo $prog /opt/bin/example $ echo $arg -D -t5 >/dev/null 1>&2 $ echo $info fdhff fd