On Fri, Jul 12, 2013 at 9:48 PM,  <gscant...@comcast.net> wrote:
> I want a script to execute the command:
> ls -alst "dir with spaces"
>
>
> The script looks like this :
> #! /bin/bash
>
> PARAMS_FOR_LS="-alst \"dir with spaces\""
>
> echo $PARAMS_FOR_LS
>
> ls $PARAMS_FOR_LS
>
>
>
> when I execute the script:
> bash -x script.sh
>
>
> I get:
> + PARAMS_FOR_LS='-alst "dir with spaces"'
> + echo -alst '"dir' with 'spaces"'
> -alst "dir with spaces"
> + ls -alst '"dir' with 'spaces"'
> ls: cannot access "dir: No such file or directory
> ls: cannot access with: No such file or directory
> ls: cannot access spaces": No such file or directory
>
> why the extra quotes ??
>
>

Quote Removal
       After the preceding expansions, all unquoted occurrences of the charac‐
       ters  \,  ', and " that did not result from one of the above expansions
       are removed.

The quotes are special for the shell only when they are literal if you
put quotes in a variable or inside other quotes, they lose their
special powers

Reply via email to