-   Linux - General (
-   -   Executing Shell Scripts? (

l0f33t 08-17-2003 07:08 AM

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.

I created a file/script called "logins", within this file I put:

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, :rolleyes:

hfawzy 08-17-2003 08:07 AM

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

smallfish 08-17-2003 09:56 AM

What exactly is a+x?
where can I read some info on a+x?

Thank you in advance for any comments.

linux fans

koyi 08-17-2003 10:45 AM


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.

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.


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.

l0f33t 08-17-2003 11:04 AM

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, :D

hfawzy 08-17-2003 11:26 AM

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 and you will find and learn a lot ;)


smallfish 08-17-2003 01:26 PM


Thank you very much. will do.

linux fans

l0f33t 08-17-2003 04:36 PM

Thanks for the reply Hfawzy.

My $PATH= when logged as as normal user:
[jbanks@localhost jbanks]$ echo $PATH

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 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

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