[英]Making an alias for `ls` that includes `echo` in csh
I want to make an alias that will add a space before and after each time I use ls
. 我想创建一个别名,在每次使用
ls
之前和之后都会添加一个空格。 If I use just ls
the result is to close to the line above and under it it I sometimes find it hard and confusing to read the output. 如果我只使用
ls
,结果是靠近上面和下面的线,我有时会觉得很难读出输出。 So I've started to use the line: 所以我开始使用该行:
echo "\n"; ls something ; echo "\n"
Is there a way to put it in an alias, so that each time I'll use the ls
command it'll automatically add the echo
commands? 有没有办法把它放在别名中,这样每次我都会使用
ls
命令它会自动添加echo
命令?
Don't have csh/tcsh available so I cannot test, but this should work 没有csh / tcsh可用,所以我无法测试,但这应该工作
alias ls 'echo "\n"; ls \!* ; echo "\n"'
Command line parameters in tcsh/csh: tcsh / csh中的命令行参数:
!!
is the whole command line !*
is all the arguments of the command !*
是命令的所有参数 !:1
is the first argument of the command !:1
是命令的第一个参数 !:2
is the second argument of the command !:2
是命令的第二个参数 !$
is the last argument of the command !$
是命令的最后一个参数 alias ls 'echo ; /bin/ls something; echo'
请注意,您必须提供ls的完整路径,否则shell会将其视为尝试再次调用别名并抱怨递归尝试。
It might be unwise to alias ls
directly, since you might use it in a script which expects the normal output. 直接别名
ls
可能是不明智的,因为您可能会在需要正常输出的脚本中使用它。 Instead, alias something like lss
in you .cshrc
: 相反,在你的
.cshrc
lss
类的别名:
alias lss 'echo; /bin/ls; echo;'
You don't need the "\\n"
because echo
alone simple prints a newline. 你不需要
"\\n"
因为echo
simple就是打印一个换行符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.