Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 816  / 3 Years ago, fri, may 14, 2021, 7:14:57

I have a private bin folder in my home directory. It's is also in my path. If I try to run a script from anywhere else in my system but within that folder, I get



  sh: 0: Can't open [name of script].sh


If I execute something like sh ~/bin/killwine.sh it works



I would like to be able to execute the script from anywhere without changing my location.



What am I doing wrong?


More From » scripts

 Answers
7

When you type sh somescript.sh, the system looks for sh in the path not somescript.sh.



Then the system finds sh and passes the argument somescript.sh to it. Then sh looks for somescript.sh in the current folder or in the specified folder ~/bin/ if you typed



sh ~/bin/somescirpt.sh. 


To make the system look for somescript.sh in the path use it directly as a command, without the sh prefix. In other words, type in the terminal:



somescript.sh


For that to work, somescript.sh needs located in a folder in the path, in this case ~/bin/ and it needs to be executable, as others have pointed out. I include the command below for completeness.



chmod +x ~/bin/somescript.sh


Also see How do I run .sh files? and



How to run scripts without typing the full path?



Hope this helps


[#22125] Friday, May 14, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
;