问题
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