How command line options work after switching the user in script?
Hello All,
I am writing a script where I need to switch to another user in the middle of the script. It goes as below Code:
echo "$HOME" Code:
/home/nagios I would be really happy if any one has any ideas on how to get this worked. |
I tried your script on my Ubuntu system, and it worked just as you expected it to. What are you running this on? Is it using bash, sh, or some other shell?
|
Thanks for the reply lykwydchykyn.
It tried with bash and sh and the result was same in both the cases. Can you paste your script and output? |
My script looked like this:
Code:
echo $HOME Code:
$ bash test.sh hello |
Variables in a HERE document are expanded by the parent shell before the text is passed to the child process. To prevent that, you can either:
A. Use a backslash escape on each of the "$" characters in the HERE document,or B. Quote any of the characters in the "EOF" marker string, e.g., Code:
sudo su - xtest <<'EOF' |
Quote:
Thanks for the reply lykwydchykyn. From your output I can say that switch user to xtest is not happening in your script. |
Quote:
I have run edited script as per your suggestion as below Code:
echo "$HOME" Code:
/home/nagios |
Quote that string (or any part of it) only where you are specifying the delimiter, not where the string occurs to mark the end of the document.
Code:
echo "$HOME" |
All times are GMT -5. The time now is 08:28 PM. |