LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-23-2011, 01:38 AM   #1
kenny53067
Member
 
Registered: Jul 2011
Location: Rio Grande City, Texas
Posts: 54

Rep: Reputation: Disabled
Question Why wont this script execute?


I have added a file named "journal-file to my home directory, and have typed this script into my terminal on my virtual machine, nothing happens. what do I have to do to get this script to execute?

$ cat journal
# journal: add journal entries to the file
# $HOME/journal-file

file=$HOME/journal-file
date >> $file
echo -n "Enter name of person or group:"
read name
echo "$name" >> $file
echo >> $file
cat >> $file
echo "------------------------------------" >> $file
echo >> $file
 
Old 07-23-2011, 01:41 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You need to have a line at the top saying what is used to interpret the script. Since it's a Bash script, you want

#!/bin/bash

at the top. You'll also need to make the script executable with "chmod +x journal".
 
1 members found this post helpful.
Old 07-23-2011, 01:42 AM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
My guess is it's probably hanging here:
Code:
cat [SOMETHING] >> $file
 
1 members found this post helpful.
Old 07-23-2011, 01:52 AM   #4
kenny53067
Member
 
Registered: Jul 2011
Location: Rio Grande City, Texas
Posts: 54

Original Poster
Rep: Reputation: Disabled
does it matter where I put #!/bin/bash or chmod +x journal ?

Do I have to use the $ and "" for these commands?
 
Old 07-23-2011, 02:13 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by kenny53067 View Post
does it matter where I put #!/bin/bash or chmod +x journal ?
The former must be the first line of the script and the latter is not put in the script. chmod is used to change permissions on a file.
 
1 members found this post helpful.
Old 07-23-2011, 02:13 AM   #6
kenny53067
Member
 
Registered: Jul 2011
Location: Rio Grande City, Texas
Posts: 54

Original Poster
Rep: Reputation: Disabled
Thank you Nylex, with your help I figured out the rest.
 
Old 07-23-2011, 02:14 AM   #7
akakingess
Member
 
Registered: Jun 2009
Location: Houston, Texas
Distribution: Ubuntu
Posts: 62

Rep: Reputation: 17
Put #!/bin/bash at the top of the script, as it designates what is used to interpret. Also, run the chmod +x journal command from the terminal while in the "home" directory (wherever the script is saved).
 
1 members found this post helpful.
Old 07-23-2011, 02:15 AM   #8
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
paulsm4 is right of course (and the comment was also made in your other thread), though.
 
Old 07-23-2011, 02:15 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by kenny53067 View Post
does it matter where I put #!/bin/bash or chmod +x journal ?

Do I have to use the $ and "" for these commands?
#!/bin/bash must be the first line of the script.

chmod +x journal is a command to run at the command prompt while in the same directory as the journal script to make it executable.

For convenience you may like to adopt the convention of naming your shell scripts with a .sh extension; it is not necessary but helps identify them.

EDIT: I don't understand the question "Do I have to use the $ and "" for these commands?"

Last edited by catkin; 07-23-2011 at 02:17 AM.
 
1 members found this post helpful.
Old 07-23-2011, 02:36 AM   #10
kenny53067
Member
 
Registered: Jul 2011
Location: Rio Grande City, Texas
Posts: 54

Original Poster
Rep: Reputation: Disabled
you saying the very first line should be #!/bin/bash ?

I'm not sure I understand where the chmod command goes.

What I meant was should there be a $ at the beginning of #!/bin bash, and should there be "" around the chmod command.
 
Old 07-23-2011, 02:39 AM   #11
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by kenny53067 View Post
you saying the very first line should be #!/bin/bash ?
Yes

I'm not sure I understand where the chmod command goes.
It doesn't go in the script (see below).

What I meant was should there be a $ at the beginning of #!/bin bash, and should there be "" around the chmod command.
No and no
Here's how the chmod command looks at a command prompt
Code:
c@CW8:~$ chmod +x journal
 
1 members found this post helpful.
Old 07-23-2011, 02:51 AM   #12
kenny53067
Member
 
Registered: Jul 2011
Location: Rio Grande City, Texas
Posts: 54

Original Poster
Rep: Reputation: Disabled
If it doesn't go in the script where does it go?

Sorry for all the questions but I'm just a little lost and I'm trying to figure this out.
 
Old 07-23-2011, 02:52 AM   #13
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
On the command line! Again, you use chmod to change the permissions on the script (i.e. who can read, write and execute it). By that logic, it doesn't make sense to put it inside the script.
 
1 members found this post helpful.
Old 07-23-2011, 02:55 AM   #14
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by kenny53067 View Post
If it doesn't go in the script where does it go?

Sorry for all the questions but I'm just a little lost and I'm trying to figure this out.
It is used as a command at the command prompt. The command prompt is displayed by the shell (usually bash) in a terminal. Which desktop are you using? Could be Gnome, KDE, Unity ... Details of how to start a terminal depend on the desktop.
 
Old 07-23-2011, 03:06 AM   #15
kenny53067
Member
 
Registered: Jul 2011
Location: Rio Grande City, Texas
Posts: 54

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Nylex View Post
On the command line! Again, you use chmod to change the permissions on the script (i.e. who can read, write and execute it). By that logic, it doesn't make sense to put it inside the script.
$ cat journal
# journal: add journal entries to the file
# $HOME/journal-file

file=$HOME/journal-file
date >> $file
echo -n "Enter name of person or group:"
read name
echo "$name" >> $file
echo >> $file
cat >> $file
echo "----------------------------------------------------" >> $file
echo >> $file

In this script, the only command line is the very first line, all the rest are script? is this correct?
 
  


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
PHP script wont execute linuxfreak3 Programming 2 07-07-2010 02:02 PM
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 02:41 AM
Pico wont run unless I execute it via dot slash, WHY? JustinK101 Linux - Software 2 01-10-2007 07:18 PM
YaST wont execute from icon on the applications menu! stephen_lewitowski SUSE / openSUSE 1 06-29-2006 10:58 AM
why wont this file and another one execute? Frustin Linux - Software 2 06-06-2002 06:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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