difference between bash variable -


i have 2 bash scripts. 1 calling another.

caller.sh

arg1="+hcpu_extra=111 bbb" str="-y +hcpu_extra=111 bbb"  local cmd_re="(-y)(.*)"  if [[ $str =~ $cmd_re ]]   opt=${bash_rematch[1]}   arg=${bash_rematch[2]}   echo "matched $opt"   echo "matched $arg" fi   ./callee.sh -y $arg  ## ./callee.sh -y $arg1 

i found if print $arg1 , $arg, show same value "+hcpu_extra=111 bbb" on screen. when pass them respectively callee.sh argument. got different results . so question , difference between $arg , $arg1 bash interpreter's point of view? .

first, code won't work right posted, because local can't used except in function.

if remove local or put in function, difference between arg , arg1 arg starts space (the 1 between "-y" , "+hcpu". since you're expanding variables without double-quotes around them, that'll removed... unless changed ifs doesn't contain space.

(btw, variable references without double-quotes , changes ifs both things can have weird effects, , best avoided when possible.)

anyway, summary is: posted code doesn't show effect you've described; appear have left out important. see how create minimal, complete, , verifiable example.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -