Parsing unique string into a variable in the posix sh shell -


i have weird behaviour can't understand; @ point need pass flags script, 1 flag in particular supposed carry out series of options used inside script, example i'm invoking script as

sh script.sh --flag1="-options1=value1 -options2=value2" --flag2 

the result is

-options1=value1 -options2=value2 1 

,and flag1 magically appears multiline declaration , happens , don't logic behind behaviour.

this complete script

parse() {   while [ $# -gt 0 ]       case "$1" in        --flag1=* ) flag_1="${1#*=}"; shift;;        --flag2   ) flag_2="1"; shift;;       (*) printf $0' : error - unrecognized option '$1'\n' 1>&2; exit 1;;     esac   done }  printvar() {   printf %s'\n' $flag_1   printf %s'\n' $flag_2 }   parse "$@" printvar 

what i'm doing wrong here ?

to flag_1 single line, quote variable:

printf "%s\n" "$flag_1" 

the below snippet should clarify:

$ printf "%s\n" ab cd ab cd $ printf "%s\n" "ab cd" ab cd 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -