Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为“创建别名”;管道grep“;_Grep_Zsh_Aliases - Fatal编程技术网

为“创建别名”;管道grep“;

为“创建别名”;管道grep“;,grep,zsh,aliases,Grep,Zsh,Aliases,我想为|grep 例如,你可以写: ps-axf G chrome而不是ps-axf|grep chrome error: must set personality to get -x option Usage: ps [options] Try 'ps --help <simple|list|output|threads|misc|all>' or 'ps --help <s|l|o|t|m|a>' for additional help text. F

我想为
|grep

例如,你可以写:

ps-axf G chrome
而不是
ps-axf|grep chrome

error: must set personality to get -x option

Usage:
 ps [options]

 Try 'ps --help <simple|list|output|threads|misc|all>'
  or 'ps --help <s|l|o|t|m|a>'
 for additional help text.

For more details see ps(1).
我在oh my zsh的别名文件中写了以下内容:

alias-g='| grep--color'

然而,这似乎不起作用

知道为什么吗

编辑

当我写
ps-axf G chrome

error: must set personality to get -x option

Usage:
 ps [options]

 Try 'ps --help <simple|list|output|threads|misc|all>'
  or 'ps --help <s|l|o|t|m|a>'
 for additional help text.

For more details see ps(1).
错误:必须设置个性才能获取-x选项
用法:
ps[选项]
试试“ps——帮助”
或者“ps——帮助”
有关其他帮助文本。
有关更多详细信息,请参见ps(1)。
似乎
G
被解释为ps命令的一部分

alias -g G=' | grep -i '
所以语法似乎还可以

所以我可以做到:-

cat file.txt G fred

您是否实际运行zsh(echo$SHELL)

您的
别名
语句在赋值之间不能有空格:

alias -g G='| grep --color'

“似乎不起作用”是模糊的。当您尝试使用别名时,会发生什么情况?同一文件中的其他别名是否正常工作?有什么
-g
选项?它意味着全局设置别名。我认为这会有帮助,但如果我使用它或者我看不出它实际上是为了Zsh,这是完全一样的对不起。如果没有grep
echo$SHELL
回馈
/usr/bin/Zsh
你知道如何在fish SHELL中实现这一点吗?@xliiv fish似乎没有真正的别名,只有函数;所以这可能是不可能的。