0

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

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

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:

x

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.

Update

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.

2

1 Answer 1

3

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:

PATH="$PATH:$HOME/myScripts"

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
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .