-   Programming (
-   -   passing quotes in shell script (

Tenor Trombone 04-18-2001 12:35 PM


I have a program that REQUIRES a comment to be provided when the program is invoked. But 9 times out of 10 my comment is an empty string. The comment is specified using the '-c' switch on the program's command line.

For example:

ci -c "this izza comment"

OK - now here's what I'd like to accomplish:

Basically, I'd like a front end script, call it cinew, that effectively makes the '-c' switch be optional. So, if I enter:


it invokes 'ci' as follows:

ci -c ""

And, if I use '-c', such as:

cinew -c "unother test"

it simply invokes 'ci' as is.

The biggest problem is that the quotes around -c's argument are lost once I'm inside the cinew script. So if I do this at the command line:

cinew -c "abc def" xyz

and my 'cinew' script contains a line:

ci $*

it gets expanded to:

ci -c abc def xyz

which is interpretted as FOUR (not THREE) arguments by the 'ci' program.

There are additional (optional) switches supported by 'ci', so I can't just hard-code quotes into the script (for example, ci $1 "$2" $3), because I can't assume that $2 will always be the comment string.

I cannot figure out a simple way to preserve the quotes and pass them off to the 'ci' program within the shell script.

I tried 'set -f' before I ran 'cinew', but that didn't change anything.

My login shell is Bash, and the script is Bourne.

Thanks for any advice,
Andover, MA

crabboy 04-18-2001 10:26 PM

Why cant you quote every parameter?

ci "$1" "$2" "$3" "$4"
ci "$@"

All times are GMT -5. The time now is 04:11 AM.