我正在尝试为命令创建别名以查看内存使用情况,
ps -u user -o rss,command | grep -v peruser | awk '{sum+=$1} END {print sum/1024}'
但是,天真的,
#.bash_aliases
alias totalmem='ps -u user -o rss,command | grep -v peruser | awk '{sum+=$1} END {print sum/1024}''
给出错误:
-bash: alias: END: not found
-bash: alias: {print: not found
-bash: alias: sum/1024}: not found
我试过用双引号,
totalmem ="ps ... |awk '{sum+=$1} END {print sum/1024}'"
, 或者
totalmem ='ps ... |awk "{sum+=$1} END {print sum/1024}"'
, 逃避,
totalmem ='ps ... |awk \'{sum+=$1} END {print sum/1024}\''
,或转义双引号......但我似乎无法让它工作。
totalmem ='ps ... |awk \"{sum+=$1} END {print sum/1024}\"'
,
给出错误
awk: "{sum+=}
awk: ^ unterminated string
任何提示表示赞赏。