Just starting off working through a bash tutorial. The first problem. A "hello world" script (say hello.sh) can be easily copied and chmodded to make it executable. The tutorial says that typing hello.sh at the terminal should run the program. It doesn't. Comes back and says "No such command". But if I type "sh hello.sh" (without quotes) it runs fine. How can I turn a script into an executable file which runs without invoking the shell?
Any help would be greatly appreciated.
bash shell script - SOLVED!
bash shell script - SOLVED!
Last edited by wimpy on Wed 14 Nov 2012, 12:24, edited 1 time in total.
LxXenial16.08, LxPupSc17.07.01,Lucid 5.2.8 and others - all frugal
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Re: bash shell script
Yes it should !wimpy wrote:...typing hello.sh at the terminal should run the program....
if its directory is found in the PATH
try
Code: Select all
echo $PATH
No !
so start your script like so:
Code: Select all
./hello.sh
Howto find out in which directory you are type
Code: Select all
pwd
Thanks for the reply. The directory I was in was /root and the file was also in there. I checked with $PATH and /root is not there. So... moved the hello.sh file to usr/bin which is in $PATH and it worked fine. .Is the omission of the current directory from the $PATH a security thing or is it easy to add a .. to $PATH?
Of course your suggestion of ./hello.sh works fine as well.
Of course your suggestion of ./hello.sh works fine as well.
LxXenial16.08, LxPupSc17.07.01,Lucid 5.2.8 and others - all frugal
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Yes it is a security thing.wimpy wrote:...Is the omission of the current directory from the $PATH a security thing or is it easy to add a .. to $PATH?...
Adding to the PATH is not recommended instead move your script to /root/my-applications/bin which is in the PATH
Code: Select all
PATH="another/directory:$PATH"
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
I should have mentioned that typing the entire file name including the path is always succesful
if hello.sh is in there again
you might also copy or just symlink it to that location
Code: Select all
/root/hello.sh
you might also copy or just symlink it to that location
@js106 Yes. I did a chmod +x .on the file and checked with a ls-la which gave
-rwxr-xr-x
Thanks for the reply.
@L18L You've removed what for me seemed to be a major roadblock.
Thanks. I'll now be able to continue with the tutorial. I'll mark this as solved
-rwxr-xr-x
Thanks for the reply.
@L18L You've removed what for me seemed to be a major roadblock.
Thanks. I'll now be able to continue with the tutorial. I'll mark this as solved
LxXenial16.08, LxPupSc17.07.01,Lucid 5.2.8 and others - all frugal