Reputation: 2551
I was wondering why I'm getting Fatal error while doing grep with [], looking for the logic here.
Working:
In [37]: run("""ps aux | grep "grunt" """)
[worker2] run: ps aux | grep "grunt"
[worker2] out: root 21414 0.0 0.0 16476 5632 pts/0 Ss+ 03:10 0:00 /bin/bash -l -c ps aux | grep "grunt"
[worker2] out: root 21475 0.0 0.0 11752 884 pts/0 S+ 03:10 0:00 grep grunt
[worker2] out:
Out[37]: 'root 21414 0.0 0.0 16476 5632 pts/0 Ss+ 03:10 0:00 /bin/bash -l -c ps aux | grep "grunt" \r\nroot 21475 0.0 0.0 11752 884 pts/0 S+ 03:10 0:00 grep grunt'
not working:
In [38]: run("""ps aux | grep "[g]runt" """)
[worker2] run: ps aux | grep "[g]runt"
Fatal error: run() received nonzero return code 1 while executing!
Requested: ps aux | grep "[g]runt"
Executed: /bin/bash -l -c "ps aux | grep \"[g]runt\" "
Aborting.
An exception has occurred, use %tb to see the full traceback.
SystemExit: run() received nonzero return code 1 while executing!
Any idea as to why the second verse is not working?
Upvotes: 1
Views: 217
Reputation: 36823
To avoid the exit 1 that grep returns, put as this:
grep "[g]runt" | tee
This is due to grep doesn't find nothing literally when using square brackets (when grunt does really run, it should work, try it)
Upvotes: 1