在bash,我曾经#输入评论.甚至在交互式会话上.
bash-3.2$ #
bash-3.2$ #
bash-3.2$ #
bash-3.2$
Run Code Online (Sandbox Code Playgroud)
csh吐出错误.如何在交互式csh会话中输入一些评论?换句话说,我正在寻找一种方法来100%肯定评论csh.
root@freebsd9:~ # #
#: Command not found.
root@freebsd9:~ # # 3e
#: Command not found.
root@freebsd9:~ # #
#: Command not found.
root@freebsd9:~ #
Run Code Online (Sandbox Code Playgroud)
交互式csh或tcsh不做评论.该#字符只有在脚本引入了注释.(这与sh及其衍生物的行为不同,例如bash.)引用csh手册页(从Solaris 9开始,其余系统之一csh不仅仅是符号链接tcsh):
当shell的输入不是终端时,字符#引入一个继续到输入行末尾的注释.它的特殊含义在前面带\或括在匹配引号中时被抑制.
我认为,关键是交互式命令不需要注释.
如果您正在使用tcsh,则可以使用内置:命令执行类似操作,该命令不执行任何操作:
% : 'This is not a comment, but it acts like one.'
Run Code Online (Sandbox Code Playgroud)
(其中%表示shell提示符并且:是命令).引用这个论点是个好主意; 否则,虽然命令没有执行,但它可能会产生一些影响:
% : This will create the file "oops.txt" > oops.txt
Run Code Online (Sandbox Code Playgroud)
请注意,由于:是命令,因此必须后跟空格.
该:命令最初是在Bourne shell的早期版本中引入的,或者甚至可能在此之前引入.
但是,该命令的/bin/csh版本:不允许任何参数,使其无法作为注释替换:
csh% : 'This will not work.'
:: Too many arguments
csh%
Run Code Online (Sandbox Code Playgroud)
(当我最初发布这个答案时,我没有意识到.我必须用tcsh测试它而不是真正的csh.)
由于:在纯csh中不起作用,下一个最佳解决方案可能是使用echo和重定向输出:
csh% echo 'This is not a comment, but it acts like one.' > /dev/null
Run Code Online (Sandbox Code Playgroud)
必要的链接:http://www.perl.com/doc/FMTEYEWTK/versus/csh.whynot
| 归档时间: |
|
| 查看次数: |
11013 次 |
| 最近记录: |