How come CD doesn't work in my shell script?

How do I do a su -c "command" so that bash comes out as the default shell.

  • please answer only with regards to total description. I need to "su" to a given user name whose default shell is "tcsh", but use a "bash" shell to execute a few shell scripts/commands which are written in "bash" and not in "tcsh".(Due to paucity of time and lack of experience I cannot convert them into "tcsh" from "bash".) I cannot use su -c <username> -s <shell name> option, because my version of solaris does not allow me the "-s" option. In effect I am trying to call something like this : $build_cmd = ("su amazon -c \"bash -c \"cd $AMAZON/buildfwrk/bin; source boo t.sh; ant usage\"\" > " ."`/opt/admin/bin/newlogf $HOME/_build.$build_area/build_logs` 2>&1"); system ($build_cmd); But given the number of double quotes I have to use, I am not sure whether the above given command will really work.Please give me the code, if you are suggesting that I write a shell script to do the same.

  • Answer:

    Good evening cheekoo1-ga, If solaris prevents you from specifying a shell using -s, perhaps you can use bash to solve your problem. What I mean is that bash accepts arguments, one of them being a file to use in lieu of standard input. So, your command could read su amazon -c "bash /home/jrandomuser/commands.txt" This way, the one command that su allows you to run is bash. So far, so good. Next you need to get bash to run commands. You simply put them in a file, one command per line, exactly as you would type them at the commandline, and save that file somewhere accessible by user amazon. Then, have bash execute that file, and you're good to go. For you, this means putting cd $AMAZON/buildfwrk/bin; source boo [... - your lines got truncated oddly] in a file somewhere (say /home/jrandomuser/commands.txt) readable by user amazon. In fact, since you're no longer limited to one line, you can separate your commands more legibly with returns than ;s. Then execute the su command I gave above. When bash finishes with the file, it encounters the EOF, which causes it to terminate. This drops you back to tcsh, but (on my Linux system) does not end your su session. Solaris may behave differently. If you need this tested, I do have access to Solaris machines (Sol/Sparc, not Solx86) at university. -Haversian

cheekoo1-ga at Google Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.