alias in cshell with grave accents, apostrophes and more

落花浮王杯 提交于 2019-12-06 08:11:31

问题


I came across a weird behavior in the c-shell: when writing the following line, i get exactly the behavior I expect:

    ls -l | grep $USER | somescript `awk -F' ' '{print $1}'`

meaning - it will search all items owned by me and activate 'somescript' with their first field as argument.

however, when I try aliasing the same line, it jams my shell (or hands out error massages if i separate the braces from the apostrophe:

    alias doit 'ls -l | grep $USER | somescript `awk -F' ' '{print $1}'`'

will result in either

{: Command not found

print: Command not found

or simply not being able to start a new terminal as it gets jammed.

any idea how can alias this thing (and similar things - this is just an example) without killing my shell?


回答1:


Welcome to the hell that is csh. I'm not sure this answer will prevent you from killing yourself, but...

% alias doit 'ls -l | grep $USER | somescript `awk -F'"'"' '"'"' '"'"'{print $1}'"'"'`'

Result:

% alias | grep doit
doit    ls -l | grep $USER | somescript `awk -F' ' '{print $1}'`

It's basically a concatenation of strings, each in alternating quotes:

'ls -l | grep $USER | somescript `awk -F'
"'"
' '
"'"
' '
"'"
'{print $1}'
"'"
'`'

(Yes, this could be simplified, but I wanted to show a consistent, general procedure for aliasing commands containing single-quotes.)



来源:https://stackoverflow.com/questions/16300776/alias-in-cshell-with-grave-accents-apostrophes-and-more

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!