这是一个示例直接程序。我正在使用 C-shell,想要一个针对此环境本身的解决方案。遵循此代码示例:
set FILENAME = "\!:2"
alias jo 'echo this is my \!:1 file and its name is $FILENAME'
在命令行上,我给出以下内容:
jo first sample.txt
我应该得到如下输出
this is my first file and its name is sample.txt
相反我得到了
this is my first file and its name is !:2
这里的问题是符号 \ 完全被消除了,我不知道该怎么做。如果我想让它接受参数,那就需要这样做。有人能帮忙吗?
答案1
为了获得所需的结果,您应该用双引号将别名的第二个参数括起来,以便正确解释变量文件名:
set FILENAME = "\!:2"
alias jo "echo this is my \!:1 file and its name is $FILENAME"
测试用例:
% jo first sample.txt
this is my first file and its name is sample.txt