alias in cshell with grave accents, apostrophes an

2020-07-20 05:06发布

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?

标签: shell alias csh
1条回答
ゆ 、 Hurt°
2楼-- · 2020-07-20 05:30

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.)

查看更多
登录 后发表回答