linux - How to pass parts of a command as variable bash? -


a="grep ssh | grep -v grep" ps -ef | $a | awk '{print $2}' 

how can make above work? have section need not pass grep term, possible pass more 1 grep term, meaning need pass "term1 | grep term2" variable.

edit:

another.anon.coward answer below worked me. thank sir!

create function instead:

a() {     grep ssh | grep -v grep } ps -ef | | awk '{print $2}' 

the other solution use eval it's unsafe unless sanitized, , not recommended.

a="grep ssh | grep -v grep" ps -ef | eval "$a" | awk '{print $2}' 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -