LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-22-2005, 10:50 AM   #1
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Rep: Reputation: 32
my first shell script doesnt work :(


Code:
#!/bin/sh
# print out the date and who's logged on
date ; who ; #should print date and who is logged on.
that is the script saved as logins.sh used anjuta to write it. when i do chmod a+x logins(.sh) either way either nothing happens and errors but i still cant run it i have tried everyway i can think of to run it its supposed to run with the command logins so i thought. anyone give me a hand with this script please
 
Old 12-22-2005, 10:56 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
How are you trying to run it or what kind of errors is it generating? It works fine for me.
 
Old 12-22-2005, 11:01 AM   #3
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Original Poster
Rep: Reputation: 32
in terminal i type chmod a+x logins and i get that it cant access no such file/dir and when i type chmod a+x logins.sh i end up back at a prompt so i try running it as logins and i get bash: logins: command not found or i try logins.sh i get same command not found im using gnome terminal assummming its a bash term.
 
Old 12-22-2005, 11:11 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
How about "./login.sh" (minus the quotes)? It's good that you just get the prompt after using chmod, that's what's supposed to happen if all is well.
 
Old 12-22-2005, 11:14 AM   #5
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Original Poster
Rep: Reputation: 32
Quote:
boxerboy@Linux:~$ ./logins.sh
Thu Dec 22 12:12:54 EST 2005
boxerboy :0 Dec 22 10:58
boxerboy pts/1 Dec 22 11:19 (:0.0)
boxerboy pts/0 Dec 22 12:12 (:0.0)
boxerboy@Linux:~$
see now that did it but shouldnt i beable to run it just by using logins atleast thats what the book uses
 
Old 12-22-2005, 11:17 AM   #6
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
If you mean you should be able to run it as "login.sh", without the "./" bit then it seems that you don't have "." (current directory) in your $PATH. If you actually mean "logins", then if you haven't got a file with that name you won't be able to run it as that.
 
Old 12-22-2005, 11:24 AM   #7
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Original Poster
Rep: Reputation: 32
ok so i can rename file just logins and i should beable to run it by typing "logins" at terminal? is that what you mean? cause thats my goal.
 
Old 12-22-2005, 11:26 AM   #8
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Yep, should do as long as "." is in your $PATH. Edit: although, how come you didn't just name the file "logins" in the first place?

Last edited by Nylex; 12-22-2005 at 11:29 AM.
 
Old 12-22-2005, 11:33 AM   #9
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Original Poster
Rep: Reputation: 32
i named it logins.sh cause i used shell script in anjuta as the file type and it added the .sh at end. ok i changed it to just "logins" its in my home dir. but i dont know how to add the . to the path.
 
Old 12-22-2005, 11:43 AM   #10
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
If you have a .bash_profile file (in your home directory), there should be a line starting with "PATH=". After the last colon, just add "." (without the quotes) and save the file.
 
Old 12-22-2005, 11:47 AM   #11
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Original Poster
Rep: Reputation: 32
i dont have a .bash_profile file all i have is desktop and this file in home.
 
Old 12-22-2005, 11:49 AM   #12
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You sure the file doesn't exist? It won't show up by just doing "ls"; you'll need "ls -a" to see it. You could change /etc/profile (but you'd need to do that as root and it would be for all users).
 
Old 12-22-2005, 11:55 AM   #13
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Original Poster
Rep: Reputation: 32
oops yeah ls didnt find it your right ls -a did find it ok now that i know i have it do i need to be saving the scripting files there? and when you said add the "." to the end of colon did you mean in the script its self? like i said im new to this
 
Old 12-22-2005, 11:57 AM   #14
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
No, in your .bash_profile, look for the line starting "PATH=" and just put a "." after the last colon.
 
Old 12-22-2005, 12:08 PM   #15
boxerboy
Member
 
Registered: Jul 2005
Distribution: ubuntu5.04, ubuntu5.10, suse9.3, mandrake10.1, mandriva2006(beta), FC1-4, redhat9.0, debian sarge
Posts: 519

Original Poster
Rep: Reputation: 32
Code:
# set PATH so it includes user's private bin if it exists
if [ -d ~/bin ] ; then
    PATH=~/bin:."${PATH}"
fi
that is last line in that file and i added the "." after /bin: and before the "$ is that where it should be?
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
why won't my shell script work :( Sanji Linux - Software 1 04-12-2005 08:10 PM
Why doesnt my simple html post to cgi script work? ginda Linux - Networking 10 03-15-2005 03:32 PM
Perl shell-out to script dunna work. Works on command line. Why? jlangelier Linux - Software 1 08-28-2004 02:00 AM
A C-shell script doesn't work on redhat 7.3 but works on Sun Solaris Belmer Linux - Newbie 2 02-08-2004 11:05 AM
Shell script won't work. Why? bruno buys Linux - Newbie 2 11-16-2003 07:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:04 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration