I'm trying to learn some more Linux, and from experience the best way is to try to bang your head against the wall. So now that I've done a task manually a few times I would like to automate it. This involves making a oneliner to kill some tasks so I can restart them.At the moment I'm working with the following:for i in `ps aux | egrep [c]ouchpotato|[s]abnzbd|[s]ickbeard|[d]eluge|[n]zbhydra|awk '{print $2, $11, $12}'`; do echo $i; doneThe thing is that as soon as I run the for loop it breaks up the lines I get from awk.Running ps aux | egrep [c]ouchpotato|[s]abnzbd|[s]ickbeard|[d]eluge|[n]zbhydra|awk '{print $2, $11, $12}'gives me the result I'm looking for, namely:27491 /usr/local/couchpotatoserver-custom/env/bin/python /usr/local/couchpotatoserver-custom/var/CouchPotatoServer/CouchPotato.py27504 /usr/local/deluge/env/bin/python /usr/local/deluge/env/bin/deluged27525 /usr/local/deluge/env/bin/python /usr/local/deluge/env/bin/deluge-web27637 /usr/local/nzbhydra/env/bin/python /usr/local/nzbhydra/share/nzbhydra/nzbhydra.py27671 /usr/local/sabnzbd/env/bin/python /usr/local/sabnzbd/share/SABnzbd    /SABnzbd.py28084 /usr/local/sickbeard-custom/env/bin/python /usr/local/sickbeard-custom/var/SickBeard/SickBeard.pyBut adding it to my for loop breaks it into: 27491/usr/local/couchpotatoserver-custom/env/bin/python/usr/local/couchpotatoserver-custom/var/CouchPotatoServer/CouchPotato.py27504/usr/local/deluge/env/bin/python/usr/local/deluge/env/bin/delugedetc...My goal is for $i to contain the whole line - is this possible? Also, is it possible to use get only the command from $11 and $12? I don't need to have the whole path to python and I don't even need to have the whole path to the application.Thanks!
Scripting with 'for' and grep/egrep
command line;awk;for;loop device;ash
Notice that the for loop output is broken apart at the word boundaries, viz., whitespaces/newlines. Whereas what you said you wanted is the whole line to come contained in the $i.So you need to do these 2 things:set the input field separator to a newline.disable the wildcards expansion.set -f;IFS=$'\n'; for i in `.....`;do echo $i; doneNote: DO NOT quote the backquotes else you shall end up giving to the for loop one big blob of argument,which would be the whole ps's output, and that doesn't do you no good.HTH