You can definitely do that (with the adjustments the others mentioned like sudo sh /pathto/script.sh
or ./script.sh
). However, I do one of a few things to run them system wide to not worry about dirs and save me useless extra typing.
1) Symlink to /usr/bin
ln -s /home/username/Scripts/name.sh /usr/bin/name
(be sure there is no overlapping name there, because you would obviously override it.) This also lets me keep them in my development folders so I can adjust as necessary.
2) Add the Scripts dir to your path (using .bash_profile - or whatever.profile you have on your shell)
PATH=/path/to/scripts/:$PATH
3) Create Alias's in the .bash_profile
in ~/.bash_profile
add something like:
alias l="ls -l"
As you can tell, the syntax is just alias, digits you want to act as a command, the command. So typing "l" anywhere in the terminal would result in ls -l
If you want sudo, just alias sl="sudo ls -l"
to note to yourself l vs sl (as a useless example).
Either way, you can just type sudo nameofscript
and be on your way. No need to mess with ./ or . or sh, etc. Just mark them as executable first :D
. /path/to/script
sources the script! You don't need the period at all if you just want to run it.