質問

I want to create an alias for an long command. But I'm not able to escape it correct, I guess it's a problem with the pipes.

My original command

ps aux | grep gimp | awk '{ print $2 '\011' $11 }' | grep -v 'grep'

My attempt for an alias

alias psa="ps aux | grep $1 | awk '{ print \$2 \"\011\" \$11 }' | grep -v 'grep'"

But I get an error that grep can not open file foo (when I do psa foo)
When I remove the last part | grep -v 'grep' then awkthrows the same error.

I prefer an alias before an shell script.

役に立ちましたか?

解決

You need to use a function if you want to to insert arguments:

psa() {
    ps aux | grep "$1" | awk '{print $2 "\t" $11 }' | grep -v grep
}

他のヒント

You can avoid all the escaping by using a function for this:

myps() {
   ps aux | grep gimp | awk '{ print $2 "\011" $11 }' | grep -v 'grep'
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top