Shell – execute shell script options

shell

I typically use cd Directory/Directory/ to point to the shell directory and then type bash shell.sh, but I was wondering if there is an easier way to execute my shell & the location with one line? I do bounce to different folders often.

Example:
unix folder with a shell script named alpha

cd Desktop/unix
bash alpha.sh

Best Answer

If you set a script file executable:

chmod o+x alpha.sh

And include the appropriate shebang (#!/bin/bash) at the top, you do not have to invoke it with bash. See man chmod for an explanation of o+x; you may prefer a+x.

As for the path, you can add that as per Rahul's suggestion, or you can do something similar without adding it to your $PATH, eg:

export SCRIPTS=~/Desktop/unix

Now anything executable in there can be used:

$SCRIPTS/alpha.sh
Related Question