Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a shell file, for example and I want to turn this into a command called wd that I can run without having to sh it, just like running cat, sort, or any other UNIX command.

How do I do this?


wd file1 file2

share|improve this question

migrated from Mar 18 '13 at 3:23

This question came from our site for professional and enthusiast programmers.

3 Answers 3

I recommend this way (using a user local ~/bin dir) :

mkdir -p bin

echo "it works"
chmod +x bin/wd
export PATH=~/bin:$PATH

(You just have to cppy/paste the whole code in the same time in a (pseudo)terminal)

To keep the PATH modified after opening another shell, use an editor to open ~/.bashrc and add the

export PATH=~/bin:$PATH


share|improve this answer
Fixed typo in post – Gilles Quenot Mar 17 '13 at 20:15
For security's sake, it's probably best to have your personal ~/bin folder at the end of your path, rather than the beginning: export PATH="$PATH:~/bin". This way if some piece of malware sneaks into it, it won't get run before an identically-named system command, for example. – MattDMo Mar 18 '13 at 3:33

Simpler solution: make an alias !

echo "alias wd='bash /somedir/somesubdir/'" >> ~/.bash_aliases
source ~/.bashrc

And you're done. You don't even need to make the script executable

share|improve this answer
Not everyone have source ~/.bash_aliases in ~/.bashrc – Gilles Quenot Mar 18 '13 at 10:04
Shell functions are preferred over aliases. – chepner Mar 18 '13 at 17:48
@chepner: preferred by you ? by yourself ? Using a function is useless in this case. – michaelmeyer Apr 10 '13 at 17:02
From the bash man page: "For almost every purpose, aliases are superseded by shell functions." – chepner Apr 10 '13 at 18:55

Simply add the path of the current folder to the ~/.bashrc

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.