[Techtalk] Shell expansion and quote removal nightmare
Brenda Bell
k15a-list-linuxchix at theotherbell.com
Mon Jan 6 19:20:25 EST 2003
Could someone either point me to a good discussion of what happens with
quotes in shell scripts (#!/bin/sh) or tell me how I can solve the
problem described below? (The last time I wrote a shell script, the OS
was called System V and the Unix Programmer's Manuals were published by
AT&T -- yes, I'm older than God :(
I'm trying to write a script that collects a bunch of data and
dynamically constructs the arguments for a tar command... like either of
the following:
tar --create --file test.tar list-of-files
tar --create --after-date "valid-date-here" --file test.tar
list-of-files
Note that the tar command may or may not use the --after-date option
depending on input to the script. Also note that the argument for
--after-date comes from a file and is in the default format you get from
date.
I incorrectly assumed I could construct a shell variable TARPARM1 whose
value is either "" or "--after-date 'valid-date-here'" and execute tar
${TARPARM1}.
I've tried various combinations of quotes and escapes and can't come up
with code that satisfies both scenarios. I have test code that echoes
the command line and it look right. When I replace the echo with tar, I
either have quotes where I don't want them or missing quotes where
they're required.
What the heck am I missing here?
More information about the Techtalk
mailing list