pid=$(pgrep 'engrampa') #Get the PID of the engrampa processes .
killpid=$(echo $pid | head -1) #Get only the first line of the $pid variable and put into a new variable called $killpid.
kill $killpid
I want to maintain only the first line of the variable $pid
.
Let's say I have 3 instances of the engrampa
process open.
When I run the commands above step by step at terminal, I get exactly what I want: 2590
https://i.stack.imgur.com/L3U2g.jpg
When I run those exaclty commands in a script I get this result: 2590 18425 18449
https://i.stack.imgur.com/RuGX9.jpg
Why is that happening?
$pid
, whereas the non-interactivebash
shell is (see for example Why are embedded newlines in command expansion replaced with whitespaces?) – steeldriver Dec 17 '18 at 23:43