I am unable to "source/run" my tcsh alias, which is as below:

alias inp1 "grep -i "final_model" /scr/cb2TempProd/tmp/$USER/\!:1/Simulation/Input/assemble.preprocessing | sed 's#.*<##; s/>$//'"
  • where \!:1 = Manual input

  • Desired Output = /scr/cb2TempProd/tmp/$USER/test/Simulation/Input/X1_X_XXXX_XXXXXX15X_H10EK011.inp

  • I will use additional alias (predefined) on Desired Output =

    alias inp2 "gdyn `grep -i "final_model" /scr/cb2TempProd/tmp/$USER/\!:1/Simulation/Input/assemble.preprocessing | sed 's#.*<##; s/>$//'`"

  • first issue = solving non-compatible variable error (while sourcing alias file)
  • second issue = can i have both outputs in single alias

In csh, the variable substitution always occurs within double quotes, and cannot be prevented by a backslash:

% echo "$"
Illegal variable name.
% echo "\$"
Variable name must contain alphanumeric characters.
% echo "\\$"
Variable name must contain alphanumeric characters.
% echo \$

This is different from the bourne shell and is documented in the manpage[1]:

After the input line is aliased and parsed, and before each command is executed, variable substitution is performed, keyed by $ characters. This expansion can be prevented by preceding the $ with a \ except within double quotes ("), where it always occurs, and within single quotes ('), where it never occurs. Strings quoted by backticks (` `) are interpreted later (see Command substitution below), so $ substitution does not occur there until later, if at all. A $ is passed unchanged if followed by a blank, tab, or end-of-line.

The easiest way out for your alias may be to start/stop the double quoting before/after the \$:

alias inp1 "grep -i 'final_model' /scr/cb2TempProd/tmp/$USER/\!:1/Simulation/Input/assemble.preprocessing | sed 's#.*<##; s/>"\$"//'"

For your second alias, I think you should simply reuse inp1 instead of trying to paste it in:

alias inp2 'gdyn `inp1 \!:1`'

[1] that's the manpage of csh, but the quotings & substitutions are absolutely similar in tcsh.

  • I did. works well. is it possible to have both outputs in one alias ? – Nayak Apr 3 at 11:44
  • you mean both inp1 and inp2? maybe alias inp3 'set v = `inp1 \!:1`; echo "$v"; gdyn "$v"' – mosvy Apr 3 at 11:48
  • klassik....works well too... :) Thank you very much for quick & correct support. – Nayak Apr 3 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.