LinuxQuestions.org
Review your favorite Linux distribution.
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 09-19-2010, 05:04 PM   #1
snowape
LQ Newbie
 
Registered: Sep 2010
Posts: 9

Rep: Reputation: 0
Newbie question


Hi all,

I am new to this, yes I am taking it for school, but I have a question. I am not asking you to do my homework, but I need help with a script.

here is an example of the script

#!/bin/bash

x=10; echo "Variable x = $x"
y=100; echo "Variable y = $y"
read -p "Press enter to continue"

echo "Now calculating x/y"
value1=$((y/x)); t=$value1
echo "the result is $value1";echo "Variable t is set to $t"
read -p "Press enter to continue"

the script will run, but I keep getting command errors, but the script does what it is supposed to. Am I missing something?

Thanks for the help,
Joey
 
Old 09-19-2010, 05:10 PM   #2
damgar
Senior Member
 
Registered: Sep 2009
Location: dallas, tx
Distribution: Slackware - current multilib/gsb Arch
Posts: 1,949
Blog Entries: 8

Rep: Reputation: 203Reputation: 203Reputation: 203
No errors here. What errors do you receive?
 
Old 09-19-2010, 06:47 PM   #3
snowape
LQ Newbie
 
Registered: Sep 2010
Posts: 9

Original Poster
Rep: Reputation: 0
it runs but it tells me "command not found"
 
Old 09-19-2010, 06:49 PM   #4
damgar
Senior Member
 
Registered: Sep 2009
Location: dallas, tx
Distribution: Slackware - current multilib/gsb Arch
Posts: 1,949
Blog Entries: 8

Rep: Reputation: 203Reputation: 203Reputation: 203
What is the entire command you are inputting into the therminal?
 
Old 09-19-2010, 07:00 PM   #5
snowape
LQ Newbie
 
Registered: Sep 2010
Posts: 9

Original Poster
Rep: Reputation: 0
sh script1.txt

The script will go work, its just throws :command not found: before every echo command, but the echo still goes through

thanks for the help btw
 
Old 09-19-2010, 07:23 PM   #6
damgar
Senior Member
 
Registered: Sep 2009
Location: dallas, tx
Distribution: Slackware - current multilib/gsb Arch
Posts: 1,949
Blog Entries: 8

Rep: Reputation: 203Reputation: 203Reputation: 203
What distro and version are you using and have you opened script1.txt to see if there are any odd characters in the actual file as it exists on your machine?
 
Old 09-19-2010, 07:26 PM   #7
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by snowape View Post
sh script1.txt

The script will go work, its just throws :command not found: before every echo command, but the echo still goes through

thanks for the help btw
Hi,

you probably created this file on a windows machine and it still has '\r\n' as newline characters. Run
Code:
sed -i 's/\r$//' script1.txt
on your file and see if it gets better.
 
Old 09-20-2010, 05:37 AM   #8
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Maybe sh is not bash. Try
Code:
bash script1.txt
Are there errors, after that command?
 
Old 09-20-2010, 07:43 AM   #9
snowape
LQ Newbie
 
Registered: Sep 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by crts View Post
Hi,

you probably created this file on a windows machine and it still has '\r\n' as newline characters. Run
Code:
sed -i 's/\r$//' script1.txt
on your file and see if it gets better.
I did create the file on a windows computer, but it was just a normal text document, I actually just typed it out in notepad.

I will try to run the above code once I get home. I will let you know how it turns out. Thanks again for all the help
 
Old 09-20-2010, 07:54 AM   #10
snowape
LQ Newbie
 
Registered: Sep 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by damgar View Post
What distro and version are you using and have you opened script1.txt to see if there are any odd characters in the actual file as it exists on your machine?
I am running it through Knoppix. Just because that is what the instructor wanted us to use.
 
Old 09-20-2010, 11:22 AM   #11
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Windows plain text files are DIFFERENT than Unix plain text files.

Windows uses a Carriage Return followed by a Newline character, Unix ises just a Newline character.

Also, Linux has no OS or filesystem-level concept of "file extensions". Shell scripts usually are named with no extension or with ".sh" to make it clear to the user at a glance that it's a shell script.
 
Old 09-20-2010, 11:30 AM   #12
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by snowape View Post
I did create the file on a windows computer, but it was just a normal text document, I actually just typed it out in notepad.

I will try to run the above code once I get home. I will let you know how it turns out. Thanks again for all the help
There are also 'dos2unix' and 'unix2dos' commands (i.e. programs) to convert line endings in text files.
 
Old 09-20-2010, 11:39 AM   #13
snowape
LQ Newbie
 
Registered: Sep 2010
Posts: 9

Original Poster
Rep: Reputation: 0
the only reason why it was names .txt is because that is what the assignment called for. I did read that most script files are .sh just for ease of scanning and finding script files.
 
  


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
Apache newbie question.. (very newbie question) tarballed Linux - Newbie 1 02-07-2003 08:41 PM
RE: Suse 8.0 hardware question {newbie question, pls help} Radiouk Linux - Distributions 2 06-04-2002 12:53 PM

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

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