Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I am able to login as a different user using a shell script in Ubuntu, but I want to run a Java program in that user, but it halts there...

for example:

  1. login as a guest user with limited permission
  2. compile
  3. java

The script I wrote:

su $USER
javac echo compiled

Kindly show me a path to solve this problem

share|improve this question

1 Answer 1

up vote 2 down vote accepted

The problem with your script is that the su $USER line invokes a subshell and so the next command doesn't execute until that subshell is exited.

You probably want to do something more like:

echo "JAVA_HOME=..." >>$USERCMDS
echo "javac" >> $USERCMDS
chmod a+x $USERCMDS
share|improve this answer
thank you sir but when i tried to run the script then i says javac command not found. i have set all the environment variables also added the java path in login.def i think its again reseting the path. –  ansh Jun 29 '12 at 6:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.