| 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. Code: su - user <<END_OF_HEREDOC
command_1 arg arg arg
command_2 $variable
END_OF_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 <<-'.'
command_1 arg arg arg
command_2 $variable
.
|