0

I would like to create executable command for Ubuntu.

I have /dir/bin/start.sh

I can execute it this way

./dir/bin/start.sh

But I was wondering how to put it to Ubuntu configuration or something, so it will be possible to invoke it from shell with just

start
3
  • export PATH=${PATH}:/path/to/dir/of/start.sh, cd /path/to/dir/of/start.sh, ln -s start.sh start. Commented May 7, 2015 at 18:55
  • @DavidC.Rankin: Or: alias start=/dir/bin/start.sh. Or start() { /dir/bin/start.sh "$@" ; } Commented May 7, 2015 at 18:56
  • Lots of way to skin that cat :p Commented May 7, 2015 at 18:57

1 Answer 1

1

You can do this by either:

  • Add the directory of the command to the $PATH variable, thus:

    export PATH=$PATH:/dir/bin
    

    To do this persistent, you must add this line to the ~/.profile file:

     echo 'export PATH=$PATH:/dir/bin' >> ~/.profile
    
  • Create a shortcut (for instance with ln -s '/dir/bin/start.sh' start) in a directory that is added to the path;

    cd <pathdirectory>
    ln -s '/dir/bin/start.sh' start
    
  • Create an alias so that the shell simply replaces the command:

    echo 'alias start=./dir/bin/start.sh' >> ~/.profile
    

How/Why does this work

If you type a command in the shell, it will first look for aliases, and replace the aliases. So if you have defined an alias for start, it will simply replace is by ./dir/bin/start.sh; so as if you have written it yourself.

Next the shell will try to find the interpretation of the command. If the command is a file (for instance by using a alias), the file is executed. Otherwise, the system falls back on $PATHs.

$PATHs is a sequence of paths where the system searches for a file with that name. It searches the paths in that order and searches through all the files for a file with the same name. If such file exists, it runs that file.

You can thus do a few things:

  • Place such program in the directory; but that's not really a nice option, because different projects are then grouped together;
  • Use a shortcut (the ln solution), in that case you only add a "representative" in the path folder;
  • Extend the number of paths by performing the PATH=$PATH:/dir/bin, so that it will search your project as well.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.