I have a csh script, which is executed using "source", and passes all its arguments to a program:
% alias foo source foo.csh
% cat foo.csh
./bar $*
# Some uninteresting stuff
If I run source foo.csh a b c
, all is OK. But not always:
foo "a b" "c d"
:
I expect bar
to get two arguments - a b
and c d
. Instead, it gets 4.
foo a "*" b
:
The *
is expanded to a list of files. I just want the character *
.
Extra credit - foo a * b
should work the same way. I know it's more problematic and I'm willing to live without it.
One thing I tried is changing ./bar $*
to ./bar "$*"
. This helps with the asterisk, but now bar
always gets everything in a single parameter.
Notes:
Our company uses csh as the login shell, so I must use it when using source
. Knowing that csh programming is considered harmful, I implemented all logic in bar
and left the bare minimum in the script.
If you suggest redefining the alias, it's important to see that redirection still works (foo | grep hello
), and that there's proper cleanup if ctrl-C breaks the script.
Meanwhile, I've found the answer myself:
./bar $argv:q
The :q
modifier takes care of things. It passes to bar
the exact same parameters foo
got.
Source: http://www.staff.tugraz.at/reinfried.o.peter/unix/cshell.html