Web lists-archives.com

Re: inotifywait in bash script: space


B.M. wrote:
>   MYCOMMAND = "inotifywait  -qqr -e create \"$MYDIR\""

I assume you later execute this by


(and that you have no blanks around the '=').

>  echo shows the command correctly

Not for me. I get already riddled in dialog:

  $ Y="a  b  c"
  $ X="echo \"$Y\""
  $ $X
  "a b c"

Obviously "echo" sees three arguments here:

I get the expected result by

  $ eval "$X"
  a  b  c

Still being riddled, my theory is that bash variable substitution happens
after quotation mark interpretation. So the marks inserted by $X stay
as they are.
The command "eval" performs a full shell parser interpretation after "$X"
got evaluated. (This might have other undesirable effects ... ponder ...)

Have a nice day :)