Pass arguments from csh to program, exactly as they are

ugoren picture ugoren · Jun 9, 2013 · Viewed 10k times · Source

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:

  1. foo "a b" "c d":
    I expect bar to get two arguments - a b and c d. Instead, it gets 4.

  2. 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:

  1. 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.

  2. 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.

Answer

ugoren picture ugoren · Jun 9, 2013

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