In Ubuntu 16.04 I have a directory nearly 10 files, each containing a single Bash script files:


Instead creating nearly 10 different aliases to each one of these files in bashrc:

alias "$HOME"/myScripts/x.sh
alias "$HOME"/myScripts/y.sh

is there a way to create one "global" alias, that will hold the path of that direcotry ("$HOME"/myScripts/) and will let me access execute each of the files, but also without their .sh extension?

For example, I'll execute in console:


and "$HOME"/myScripts/x.sh will be executed.

I wouldn't really use a non intuitive name like x, it's just for example.

The minor problem to solve here is to save the amount aliases, easing their maintenance. The more one works with directories dedicated to some contexts of software, the more this method would be handy, I assume.


In the end what I did is to create a file with many Bash functions, I then sourced the file, and then exported the functions in it:

export -f myFunc_0 myFunc_1 ...

There might be a simple global way to export these but I don't know of one.


You could add the directory to your path, which would let you type x.sh from anywhere without needing an alias.

In ~/.bashrc for example:


There is no need to have an extension so you could just rename the script from x.sh to x.

mv ~/myScripts/x.sh ~/myScripts/x

Alternatively you could make a symlink from your script to somewhere in your path, like /usr/local/bin, and name the link x.

ln -s /home/user/myScripts/x.sh /usr/local/bin/x

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.