Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

We have:

  1. a user nico.
  2. a folder /home/nico/script_home with some bash scripts:

    1. main.sh
    2. subscripta.sh
    3. sqlscripta.sh
  3. We connect as root and cd /home/nico/script_home/

  4. Finally we run ./main.sh

We get as a result:

  1. subscripta.sh - no such file or directory
  2. The sql script works fine

I noticed that su - nico -c "pwd" returns /home/nico/ So I tried changing main.sh to ./script_home/subscripta.sh but to no avail.

What is the right syntax to avoid the no such file or directory error when running a script with su -?

su - nico -c "./subscripta.sh"
su - nico -c "sqlplus username/pass@some_oracle_db @script_home/sqlscripta.sql"
share|improve this question

2 Answers 2

up vote 1 down vote accepted

Try su - nico -c "/home/nico/script_home/subscripta.sh"

share|improve this answer
yeah I tried that. I need to run my scripts again to let you guys know what worked or not. That way it will funnel the answers a bit. –  ndefontenay Dec 17 '11 at 15:43
As I've wrote, put whole path inside "". You can try of course with some variables like $HOME/script_home/subscripta.sh ... Question is how this script is built and if there are all paths done as they should be? –  Sebastian Szary Dec 17 '11 at 23:31

Don't do su - - that does a total login for the user ID, including setting HOME to whatever user ID's home directory is.

Try su nico -c "./script.sh"

Also, ensure that script.sh is marked executable.

share|improve this answer
Oh nice. This is a great tip. But to run stuff on oracle, I do need to call my oracle's user profile bash_profile has a number of variable exported which allows to call sqlplus etc... –  ndefontenay Dec 18 '11 at 2:19

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.