-1

I would like to run ".sh" files in a directory without having to navigate to that directory, as shown below.

Me trying to run a .sh file, that is not in my current directory:

root@naveen-hp:/home# bash start-master.sh
bash: start-master.sh: No such file or directory

Me trying to run a .sh file by specifying it's location:

root@naveen-hp:/home# bash /usr/local/bin/spark/sbin/start-master.sh
starting org.apache.spark.deploy.master.Master, logging to /usr/local/bin/spark/logs/spark-root-org.apache.spark.deploy.master.Master-1-naveen-hp.out 

So, is there a way to have terminal to also look in /usr/local/bin/spark/sbin/ directory, not just the pwd, when a request to run a .sh file is sent?

  • variable $PWD will have the present working directory – guiverc Oct 30 '20 at 11:30
  • yes, pwd will have present working directory. I want bash to look also inside /usr/local/bin/spark/sbin whenever i run a .sh file. – Naveen Reddy Marthala Oct 30 '20 at 11:32
  • 1
    You will first need to get out of the habit of running scripts with bash (or sh, or csh, or ...) explicitly - it's the job of the shebang to decide what interpreter to use. Once you make the script executable, THEN you can add /usr/local/bin/spark/sbin/ to your PATH. The shell only searches your path for programs, not for arguments to programs - which is what you use bash explicitly. – steeldriver Oct 30 '20 at 12:21
  • sure @steeldriver. I haven't been able to add that directory to my path. i have copy-pasted many scripts from internet, but to no avail. – Naveen Reddy Marthala Oct 30 '20 at 12:24

1 Answers1

1

You have to add the path you want to contain the script file(s) to you PATH variable.

Look here for example: How to add a directory to the PATH?

wudu
  • 86