| Author |
Message |
wimpy

Joined: 22 Aug 2012 Posts: 106 Location: Essex, UK
|
Posted: Wed 14 Nov 2012, 05:52 Post subject:
bash shell script - SOLVED! |
|
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.
_________________ Lucid 5.2.8 CD and USB stick
Last edited by wimpy on Wed 14 Nov 2012, 08:24; edited 1 time in total
|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 1721 Location: Burghaslach, Germany
|
Posted: Wed 14 Nov 2012, 07:05 Post subject:
Re: bash shell script |
|
| wimpy wrote: | | ...typing hello.sh at the terminal should run the program.... |
Yes it should !
if its directory is found in the PATH
try
is it?
No !
so start your script like so:
which will work if you are in the same directory as your script hello.sh
Howto find out in which directory you are type
Hope that helps
|
|
Back to top
|
|
 |
wimpy

Joined: 22 Aug 2012 Posts: 106 Location: Essex, UK
|
Posted: Wed 14 Nov 2012, 07:24 Post subject:
|
|
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.
_________________ Lucid 5.2.8 CD and USB stick
|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 1721 Location: Burghaslach, Germany
|
Posted: Wed 14 Nov 2012, 07:46 Post subject:
|
|
| wimpy wrote: | | ...Is the omission of the current directory from the $PATH a security thing or is it easy to add a .. to $PATH?... |
Yes it is a security thing.
Adding to the PATH is not recommended instead move your script to /root/my-applications/bin which is in the PATH
| Code: | | PATH="another/directory:$PATH" |
would prepend another/directory to the PATH
|
|
Back to top
|
|
 |
jsl06
Joined: 02 Mar 2012 Posts: 9
|
Posted: Wed 14 Nov 2012, 08:01 Post subject:
chmod Subject description: bash shell script |
|
Even though you mention chmod in in your post, you do not say that you performed chmod on the file. chmod makes the file eaecutable. Perform ls on the file. You should see an x in the description. If not, chmod +x hello.sh.
|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 1721 Location: Burghaslach, Germany
|
Posted: Wed 14 Nov 2012, 08:13 Post subject:
|
|
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
|
|
Back to top
|
|
 |
wimpy

Joined: 22 Aug 2012 Posts: 106 Location: Essex, UK
|
Posted: Wed 14 Nov 2012, 08:22 Post subject:
|
|
@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
_________________ Lucid 5.2.8 CD and USB stick
|
|
Back to top
|
|
 |
|