Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 12 of 12
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11


    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.

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

    su - user <<-'.'
    	command_1 arg arg arg
    	command_2 $variable

  2. #12
    Linux User
    Join Date
    Jul 2007
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts