Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Ubuntu Lucid Lynx, I'm trying to do

su -l user -c "foo.sh args"

where foo.sh is an executable bash script on the PATH set in ~user/.bashrc. Unfortunately, this fails because it can't find foo.sh. If I su -l user and manually type foo.sh args at the command line, it works fine. The PATH augmentation is done in ~user/.bashrc and appears to work whether or not I su with -l interactively, but it doesn't appear to work when I specify the command.

Any idea why this is, and how I can get around that?

share|improve this question
add comment

1 Answer 1

It's starting the shell as a non-interactive login shell so it processes ~/.profile and not ~/.bashrc. You can set your PATH in that file or do it in a common file that both of them source. Some people/distributions set one startup file to source the other one, but I don't recommend this.

From man bash:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes com‐ mands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

share|improve this answer
add comment

Your Answer

 
discard

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.