cshell中的别名带有重音符号,撇号等 [英] alias in cshell with grave accents, apostrophes and more

查看:113
本文介绍了cshell中的别名带有重音符号,撇号等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C壳中遇到了一个奇怪的行为:
在编写以下行时,我得到的正是我期望的行为:

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}'`'

将导致


{:找不到命令

{: Command not found

print:找不到命令

print: Command not found

或根本无法启动新终端,因为它被卡住了。

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

任何想法都该如何别名(和类似的东西-这只是一个例子)而不会杀死我的shell?

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

推荐答案

欢迎来到<$ c $的地狱c> csh 。我不确定该答案是否会阻止您自杀,但...

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}'"'"'`'

结果:

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

这篇关于cshell中的别名带有重音符号,撇号等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆