简体   繁体   中英

How to copy a .sh file to 'bin/sh/'

I am trying to copy a .sh file into 'bin/sh' directory, but I am not able to access 'sh'. Is there any way or command to copy .sh file to 'sh' directory?

If you make your own sh script and want it to be found and executed from your shell prompt you:

  • Change rights for the script file myscript.sh

    chmod +w myscript.sh

or

chmod 755 myscript

etc.. depending on who is allowed to execute and change the script.

  • You can copy the file to /bin/ (not recommended) or /usr/bin (not as bad, and the place to put it possibly if you have more users than yourself on the system) or you add a new path where you keep your sh scripts into the PATH environment. If you run bash it is in ~/.bashrc.

You can test this from the prompt before changing .bashrc if you (example in bash) do

export PATH=$PATH:~/myscripts/

For scripts you have put in your own directory myscripts. To put it into /usr/bin you do

sudo cp myscript.sh /usr/bin/.

If you do not have any sudo rights, you are bound to the latter solution with a directory of your own where you put your sh files and changing the PATH.

  • Recommended to study: read up on the man pages for chmod and bash. Also on changing environment variables.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM