I am trying to get the name of the shell executing a script.
Why does
echo $(ps | grep $PPID) | cut -d" " -f4
work while
echo ps | grep $PPID | cut -d" " -f4
does not?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The reason is that
just prints out the string
ps; it doesn’t run the programps. The corrected version of your command would be:Edited to add: paxdiablo points out that
ps | grep $PPIDincludes a lot of whitespace that will get collapsed byecho $(ps | grep $PPID)(since the result of$(...), when it’s not in double-quotes, is split by whitespace into separate arguments, and thenechooutputs all of its arguments separated by spaces). To address this, you can usetrto “squeeze” repeated spaces:or you can just stick with what you had to begin with. 🙂