Unable to get the value to a variable.
set -x
cd $HOME
echo "Enter the server name"
read a
echo $a
i=4
j=1
k = ps -ef | awk '/server1/{ print $4 }' | tail -$i | head -$j`
echo $k
When I do the same in command line it works, however the same does not work when I provide that in the script. I hope this is a syntax issue. Would be great if you can suggest.
Code tags for code, please.
```text
stuff
```
This line is wrong:
k = ps -ef | awk '/server1/{ print $4 }' | tail -$i | head -$j`
It will misbehave in both, but you may not have realized the difference:
k=`ps -ef | awk '/server1/{ print $4 }' | tail -$i | head -$j`
You shouldn't put extra spaces around the equal sign. (You were also missing a `, but I'm assuming that was just a typo.) Unlike some other languages, shell code has a specific, different meaning for that, like:
VARIABLE="value" command
...to temporarily export VARIABLE into the environment, just for command.