tags:

views:

105

answers:

4

Hi,

I was wondering if it is possible to make a "link" in usr/bin (i.e.) that leads to a shell-script.

But I want just to write

% shellscript

instead of

% sh shellscript.sh

kinda like an alias.

Is this possible?

+1  A: 

You can make the shell script executable (chmod +x shellscript.sh). Then you can link to it from /usr/bin (ln -s shellscript.sh /usr/bin/shellscript).

Jeff
+1  A: 

Yes. You can use ln to create a link to shellscript.sh named shellscript. You will then need to make it executable, but after that (assuming /usr/bin is on your path) you can run it with shellscript.

VeeArr
thanks for explaining the linking-alternative!
ShoX
+2  A: 

In addition to making the script executable and linking it into /usr/bin, as others have suggested, you will also want to add the "shebang" line to the top of the script:

#!/bin/sh

# your commands here

This lets you specify which shell interpreter (bash, bourne shell, c-shell, perl, python...) should be used to execute your script.

Jim Lewis
+5  A: 

Make the first line of the script

#!/bin/sh

Then make it executable:

chmod +x shellscript.sh

You don't need the .sh on the end of the script's filename.

If you now place the script in a bin folder that is on your system's PATH variable and you will be able to run it directly. To see the folders in your path, type:

echo $PATH;

I usually use /home/[my username]/bin for scripts that I have written so that they don't interfere with other users on the system. If I want them to be for all users, I use /usr/local/bin which is supplied empty on most distributions.

rjmunro
Thanks for your detailed description
ShoX