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?
For shell scripts without execute permissions, you will need to pass the script as an argument to your choice of interpreter. Here the execute permissions are checked for your shell interpreter and not the script itself. So you should have execute for /bin/sh and your script can have only read permissions.
As long as bash is executable, you can always run bash with the script file as argument, or run bash interactively and copy paste the script line by line into your terminal to have the commands executed.
Make the first line of the script
#!/bin/sh
Then make it executable by typing the command:
chmod +x shellscript.sh
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.
The .sh
on the end of the script's filename is only a convention to help you remember what kind of file it is. It will still work if you rename it to just shellscript
, for example, which will complete your requirements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With