Linux 为具有管道的监视命令添加别名

Linux 为具有管道的监视命令添加别名,linux,bash,unix,ubuntu-16.04,Linux,Bash,Unix,Ubuntu 16.04,我想为下面的命令使用名为fdbtop的别名 watch -tc 'fdbcli --exec "status json" | python /home/ubuntu/build-target/healthservice/fdbtop.py' 我尝试在.bash\u别名中添加以下行 alias 'fdbtop=watch -tc \''fdbcli --exec "status json" | python /home/ubuntu/build-target/healthservice/fdbt

我想为下面的命令使用名为
fdbtop
的别名

watch -tc 'fdbcli --exec "status json" | python /home/ubuntu/build-target/healthservice/fdbtop.py'
我尝试在
.bash\u别名中添加以下行

alias 'fdbtop=watch -tc \''fdbcli --exec "status json" | python /home/ubuntu/build-target/healthservice/fdbtop.py\'''
但它给了我以下的错误

ubuntu@vrni-platform:~$ fdbtop
python: can't open file '/home/ubuntu/build-target/healthservice/fdbtop.py ': [Errno 2] No such file or directory
                                                                                                                 ubuntu@vrni-platform:~$
文件已存在

ubuntu@vrni-platform:~$ ls /home/ubuntu/build-target/healthservice/fdbtop.py
/home/ubuntu/build-target/healthservice/fdbtop.py
有人能告诉我怎么做吗


操作系统版本-Ubuntu 16.04

正如anubhava所提到的,这更适合于函数。您可以像添加别名一样添加它(通常在.bashrc文件中,但如果愿意,您可以源代码获取特定于函数的文件)


在单引号中的字符串中,没有特殊字符。要在单引号中的字符串中插入单引号,必须使用
'\''
。(第一个
'
终止字符串,
\'
添加一个引号,最后一个
'
再次打开字符串。)

使用shell函数而不是单个引号内的别名,单个引号是
'\'
。检查您的字符串语法。@AlexP您能将此作为答案发布吗?我理解你的意思
别名'fdbtop=watch-tc'\'fdbcli--exec“status json”| python/home/ubuntu/build target/healthservice/fdbtop.py'\''''\'''
注意
函数funcname{
是传统的(POSIX之前的)ksh语法,而
funcname(){
是与POSIX兼容的函数声明。将两者结合起来,可以得到既不兼容POSIX也不兼容旧版ksh的结果;请参阅Yeah上的讨论。我知道。谢谢,CD。
function fdbtop() { 
    watch -tc 'fdbcli --exec "status json" | python /home/ubuntu/build-target/healthservice/fdbtop.py' 
} 
alias fdbtop='watch -tc '\''fdbcli --exec "status json" | python /home/ubuntu/build-target/healthservice/fdbtop.py'\'