bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: quotes in bash script


From: Pierre Gaston
Subject: Re: quotes in bash script
Date: Sat, 13 Jul 2013 08:57:06 +0300

On Fri, Jul 12, 2013 at 9:48 PM,  <address@hidden> 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

[Prev in Thread] Current Thread [Next in Thread]