2

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?

  • If I understood correctly your question, you want to use a variable as part of the alias command, expanding it at runtime with its value. By the way: welcome to AskUbuntu! – 0x2b3bfa0 Aug 26 '18 at 16:41
  • yes its correct. thankfully for the solution. unfortunately i have to work with csh so its kinda difficult to find solutions for such minor things and glad to be here :) – Jovin Miranda Aug 27 '18 at 0:51
1

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
| improve this answer | |
  • If this asnwer solved your question, please mark It as accepted by clicking the tick mark on the left and (optionally) upvote it with the up-pointing arrow. If you prefer to wait for another answer, feel free to wait more time. If you need any additional explaination or clarification, don't hesitate to comment here. – 0x2b3bfa0 Aug 27 '18 at 13: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.