Results 11 to 12 of 12
The problem you're having is due to the fact that su starts it's own shell and that shell gets its own input, not the remaining lines in your script. To ...
- 01-23-2009 #11Just Joined!
- Join Date
- Jan 2009
- Posts
- 1
heredocs
The problem you're having is due to the fact that su starts it's own shell and that shell gets its own input, not the remaining lines in your script. To put some of your script lines into the su stdin, you can use a heredoc.
Note that the $variable will be interpolated in the script's shell prior to sending it as stdin to su. To prevent that, put END_OF_HEREDOC in quotes on the su line, but not at the end of the heredoc. You can also add a dash ("-") between the << and END_OF_HEREDOC if you like which will cause any initial tabs (but not spaces) to be removed from the lines of the heredoc. And of course, your END_OF_HEREDOC designator can be pretty much any string including a simple period. All that together would look like:Code:su - user <<END_OF_HEREDOC command_1 arg arg arg command_2 $variable END_OF_HEREDOC
Code:su - user <<-'.' command_1 arg arg arg command_2 $variable .
- 01-23-2009 #12Linux User
- Join Date
- Jul 2007
- Location
- Greece
- Posts
- 277
Hello uberbaud
I just find out about heredoc by reading your post. Thank you for sharing that.
It's new to me and looks useful.



