[Techtalk] Shell expansion and quote removal nightmare

Brenda Bell k15a-list-linuxchix at theotherbell.com
Mon Jan 6 23:04:40 EST 2003


Almut Behrens wrote:
> the trick is to use an "eval" in front of the tar command, e.g.
> 
>   #!/bin/bash
>   
>   AFTERDATE="--after-date '`date -d yesterday`'"
>   
>   eval tar --create $AFTERDATE --file test.tar *
> 
> The first interpolation (variable expansion) happens when the
> arguments for the eval get prepaired. The second interpolation
> during the execution of the eval then realises that the substring
> 'Mon Jan 6 02:24:32 CET 2003' is only *one* argument. Without the
> eval, the shell passes all (space-separated) arguments individually
> as single entities to tar, and tar itself does not handle quoting
> across multiple arguments. You can observe this behaviour using
> strace (-f), which shows you something like
> 
> ...
> execve("/bin/tar", ["tar", "--create", "--after-date", "\'Mon", "Jan", "6", "02:24:32", "CET", "2003\'", "--file", "test.tar", ...
> 
> Whether you call this a bug or not is up to you... ;)

I'd at least call it non-intuitive...  but you're most definitely my hero!!!

Thanks.




More information about the Techtalk mailing list