Unable to use variables in alias in cshell
Matthew Barrera
This is a sample straight forward program. I am using C-shell and want a solution for this environment itself. Following this code sample:
set FILENAME = "\!:2"
alias jo 'echo this is my \!:1 file and its name is $FILENAME'on command line when I give the following:
jo first sample.txtI should get the output as
this is my first file and its name is sample.txtinstead I get
this is my first file and its name is !:2The problem here is the symbol \ totally gets eliminated, I don't know how. That is needed if I want it to take the argument. Can anyone help out with this?
21 Answer
To achieve the desired result, you should wrap the alias' second argument with double quotes, so the variable filename gets interpreted correctly:
set FILENAME = "\!:2"
alias jo "echo this is my \!:1 file and its name is $FILENAME"Test case:
% jo first sample.txt
this is my first file and its name is sample.txt 1