Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 19 Dec 2014, 03:28
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
bash shell script - SOLVED!
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
wimpy


Joined: 22 Aug 2012
Posts: 304
Location: Essex, UK

PostPosted: 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 ,Precise, Carolina, Shiba_inu, Lx_pup - all frugal

Last edited by wimpy on Wed 14 Nov 2012, 08:24; edited 1 time in total
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2610
Location: www.eussenheim.de/

PostPosted: 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
Code:
echo $PATH

is it?

No !

so start your script like so:
Code:
./hello.sh

which will work if you are in the same directory as your script hello.sh

Howto find out in which directory you are type

Code:
pwd


Hope that helps
Back to top
View user's profile Send private message 
wimpy


Joined: 22 Aug 2012
Posts: 304
Location: Essex, UK

PostPosted: 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 ,Precise, Carolina, Shiba_inu, Lx_pup - all frugal
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2610
Location: www.eussenheim.de/

PostPosted: 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
View user's profile Send private message 
jsl06

Joined: 02 Mar 2012
Posts: 9

PostPosted: 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
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2610
Location: www.eussenheim.de/

PostPosted: Wed 14 Nov 2012, 08:13    Post subject:  

I should have mentioned that typing the entire file name including the path is always succesful

Code:
/root/hello.sh

if hello.sh is in there again

you might also copy or just symlink it to that location
Back to top
View user's profile Send private message 
wimpy


Joined: 22 Aug 2012
Posts: 304
Location: Essex, UK

PostPosted: 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 ,Precise, Carolina, Shiba_inu, Lx_pup - all frugal
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0521s ][ Queries: 12 (0.0036s) ][ GZIP on ]