Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

Unable to use variables in alias in cshell

Writer 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.txt

I should get the output as

this is my first file and its name is sample.txt

instead I get

this is my first file and its name is !:2

The 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?

2

1 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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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