LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-17-2003, 06:08 AM   #1
l0f33t
Member
 
Registered: May 2003
Location: Washington State
Distribution: Gentoo
Posts: 145

Rep: Reputation: 15
Question Executing Shell Scripts?


If I create a simple Shell script, i.e.. [filename="logins"] with two simple commands. date and cal and I want to execute this basic shell script why cant I just type in [name file to be executed]

I'm running MDK 9.0. and using BASH shell.

Example.
I created a file/script called "logins", within this file I put:
#!bin/bash
cat
date

So to run this script I first changed the permisision on the file to be a+x.

But when I type in logins all by itself I get:
[root@localhost SS]# logins
bash: logins: command not found

If I type "bash login then the file executes the commands within the login file. Simple shell script.

If I try to specifiy ./logins I get back:
[jbanks@localhost SS]$ ./logins
bash: ./logins: bin/bash: bad interpreter: No such file or directory

Why am I not able to just specify the "logins" and have it execute?

Thanks,
 
Old 08-17-2003, 07:07 AM   #2
hfawzy
Member
 
Registered: Aug 2002
Location: Egypt
Distribution: Debian Sarge, Slackware 10.0
Posts: 163

Rep: Reputation: 30
You have made a mistake in the first line of your script, replace #bin/bash with #/bin/bash (notice the first slash). This should solve the problem when executing ./logins

If you want to type logins in the command line without ./ , you have to copy your script to /usr/bin or whatever path that is in your PATH.
btw, to view all pathes in your PATH variable, just type "echo $PATH"

Hope this helps
 
Old 08-17-2003, 08:56 AM   #3
smallfish
Member
 
Registered: Feb 2003
Location: Hong Kong, China
Distribution: redhat 8
Posts: 36

Rep: Reputation: 15
What exactly is a+x?
where can I read some info on a+x?

Thank you in advance for any comments.

smallfish
linux fans
 
Old 08-17-2003, 09:45 AM   #4
koyi
Member
 
Registered: Jul 2003
Location: Osaka, Japan
Distribution: Arch, Ubuntu
Posts: 421

Rep: Reputation: 31
Quote:
Originally posted by smallfish
What exactly is a+x?
where can I read some info on a+x?

Thank you in advance for any comments.

smallfish
linux fans
It is something to do with file permissions. Try to read the man page of chmod, though I am not sure if it is written there.

Basically any file/directory in linux has 3 permissions, which are the permission to read, the permission to write and the permission to execute/run. Try to run the command "ls -l" and you should be able to see something like this on the left.

-rwxrwxrwx

These are the permissions of a file. r stands for read, w for write and x for execute. The first 3 letters tell about the permissions of the owner of the file on it. The second 3 letters specify the permissions of the group that the file belongs to. The last 3 letters set the permissions of other people on that file.

Now, you can change the permissions of the file using chmod. And "chmod a+x" give the execute permission to all users. (a for all) Read more on this in any linux book.
 
Old 08-17-2003, 10:04 AM   #5
l0f33t
Member
 
Registered: May 2003
Location: Washington State
Distribution: Gentoo
Posts: 145

Original Poster
Rep: Reputation: 15
Thanks Hfawzy,

Good eye.....
Attention to detail is the name of the game in the Unix/linux world.

So now I'm wondering why it is that I have to have my "logins" script located in the /usr/bin directory for it to execute when only specifying the script by script file name?

I have two books that I'm going through right now about shell scripting, and I don't beleave that the mention this little tidbit. Any "DOC'S" that you can point me to that do mention this will help?

I'm just learning. So any helpful hints are welcome.

Thanks Hfawzy,
 
Old 08-17-2003, 10:26 AM   #6
hfawzy
Member
 
Registered: Aug 2002
Location: Egypt
Distribution: Debian Sarge, Slackware 10.0
Posts: 163

Rep: Reputation: 30
When you execute a program without ./ , your system tries to find the requested program located in your PATH. The PATH enviroment variable contains some pathes, these pathes are delimited with ":". So, if you move your script from /usr/bin to any other path in your PATH, this will also work.

If you want to find any documentation/tutorial related with any subject in linux (enviroment variables...), just search www.google.com/linux and you will find and learn a lot

HTH
hfawzy

Last edited by hfawzy; 08-17-2003 at 02:16 PM.
 
Old 08-17-2003, 12:26 PM   #7
smallfish
Member
 
Registered: Feb 2003
Location: Hong Kong, China
Distribution: redhat 8
Posts: 36

Rep: Reputation: 15
Smile

Koyi

Thank you very much. will do.

smallfish
linux fans
 
Old 08-17-2003, 03:36 PM   #8
l0f33t
Member
 
Registered: May 2003
Location: Washington State
Distribution: Gentoo
Posts: 145

Original Poster
Rep: Reputation: 15
Thanks for the reply Hfawzy.

Ok....so............

My $PATH= when logged as as normal user:
[jbanks@localhost jbanks]$ echo $PATH
/usr/X11R6/bin:/usr/local/bin:/bin:/usr/bin

When logged in as root:
[root@localhost jbanks]# echo $PATH
/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin


.....so because the location of the "logins" script is located at /home/jbanks/SS this isn't in either the local users path or roots path? Correct or not?
I'm pretty sure this is correct....

So just out of example, (and I'm sure they're are other ways to do this) from my local user, (non-root), to get the "logins" script to execute just by typing "logins" I would need to add /home/jbanks/SS to my $PATH, or just /home?
Just unsure if I put /home, will it decend through the /home directory and all of its subdirectories?

Thanks for helping me get a grip on this. Much appreaciated :P
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stop konqueror executing shell scripts ahh Linux - Software 2 03-27-2005 06:00 AM
CGI Scripts not executing, pls help john_d13 Linux - General 3 12-22-2004 02:05 PM
Prevent konqueror from executing shell scripts Dave Farrance Mandriva 1 05-30-2004 08:37 PM
Executing scripts upon login jungatheart Linux - Newbie 3 04-19-2004 06:06 PM
Executing shell scripts justinv Linux - General 6 01-26-2003 07:57 AM


All times are GMT -5. The time now is 06:47 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration