0

I am trying to make an init.d script to launch my app. I have two scripts, the first one is the init.d script myapp :

   #!/bin/bash
   export MYAPP_HOME="/srv/myapp"
   su - myuser -c "exec $COMMAND_LINE"

The second is a script to launch myapp.

I want to use the variable MYAPP_HOME in the second script.

Can anybody help me ?

2
  • 1
    Your su command can't access the environment of the caller, so your exported variable will not be available. You would need to pass it as a command line argument. Commented Sep 11, 2012 at 10:11
  • @MikeWeller, thats simply not true. su <username> -c "<command>" inherits the current environment. The OP's issue is that they had -, specifying a login shell. Commented Sep 12, 2012 at 17:17

1 Answer 1

4

The problem is that you are creating a login shell by using the - argument to su, so a new environment is created. Either don't use a login shell (omit the -), pass the variable as a command-line argument, or place the environment variable in one of the start-up files, like .bash_profile.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.