executing shell script without calling sh implicitly

后端 未结 5 1163
夕颜
夕颜 2021-02-01 18:05

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
5条回答
  •  天涯浪人
    2021-02-01 18:33

    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.

提交回复
热议问题