LinuxQuestions.org
Help answer threads with 0 replies.
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 03-21-2004, 08:36 PM   #1
Corallis
Member
 
Registered: Jan 2004
Location: EST
Distribution: Slackware 10.0
Posts: 150

Rep: Reputation: 15
Simple shell script problem?


I am currently following a Linux tutorial and right now I am trying to learn about shell scripts. The tutorial instructed me to make a new .sh file, so I made a file called test.sh. I was then supposed to use the command "chmod 755 test.sh", and I did. Next, I had to add the following lines of code to the file:
Code:
#!/bin/sh
echo "Hi there"
echo "what is your name? (Type your name here and press Enter)"
read NM
echo "Hello $NM"
I put these lines of code in, and saved the file. Next, I was told to execute the script by using the ./test.sh command. However, this resulted in the following error:

corallis@home1:~/Desktop$ ./test.sh
./test.sh: line 2: echo Hi there: command not found
./test.sh: line 3: echo what is your name? (Type your name here and press Enter): command not found
./test.sh: line 4: read NM: command not found
./test.sh: line 5: echo Hello : command not found

Im really stumped as to why this is happening. Im very new to linux, Ive been using windows for the last 8 years. It seems to me as though I might be missing a file of some sort that contains the shell scripting source code, or maybe a path that is supposed to point to the shell scripting source code is incorrect. Then again, Im just assuming there is some sort of shell scripting source code, so I could be way off. Thanks to anyone in advance who can help me.
 
Old 03-21-2004, 08:46 PM   #2
snacky
Member
 
Registered: Feb 2004
Distribution: Debian
Posts: 286

Rep: Reputation: 30
1. /bin/sh exists, right? Make sure.
2. Creating a file, THEN adding to it, is a little bit odd. Can you do "cat test.sh" to verify that the above lines are the ONLY contents of the file? It works fine for me...
 
Old 03-21-2004, 08:54 PM   #3
Corallis
Member
 
Registered: Jan 2004
Location: EST
Distribution: Slackware 10.0
Posts: 150

Original Poster
Rep: Reputation: 15
corallis@home1:~/Desktop$ cat test.sh
#!/bin/sh
echo "Hi there"
echo "what is your name? (Type your name here and press Enter)"
read NM
echo "Hello $NM"

Thats the output of "cat"ing the file. Also, I checked and /bin/sh does exist. I went into the /bin folder and found a green sh@ file inside of it. Am I correct to assume that is the file that is required?
 
Old 03-21-2004, 11:25 PM   #4
liamoboyle
Member
 
Registered: Mar 2004
Location: Wellington, New Zealand
Distribution: Debian
Posts: 127

Rep: Reputation: 15
Try typing in 'sh test.sh' ... if that works, then it isn't telling sh to interpret your file right.

What is the output of ls -l /bin/*sh? It needs to be executable, so it should look something like
-rwxr-xr-x 1 root root 614K 2004-02-23 01:47 /bin/sh
or
lrwxrwxrwx 1 root root 4 2004-02-24 09:57 /bin/sh -> bash

if it isn't executable, you have issues.
I'd generally recommend using /bin/bash instead of /bin/sh, bash is the latest revision.
 
  


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
Problem with simple shell script for loop abefroman Programming 2 10-25-2005 08:26 PM
Simple shell script mikz Linux - General 1 02-24-2005 07:18 AM
simple shell script sharpie Programming 9 06-02-2004 11:47 PM
simple shell script Greg_courageous Programming 2 05-12-2004 04:34 PM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM

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

All times are GMT -5. The time now is 10:55 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