Results 1 to 7 of 7
Write the fist hello.sh bash script as follows:
--------------------------------
# hello.sh
# This is my first shell script
printf "Hello! Bash is wonderful."
exit 0
--------------------------------
# bash hello.sh
: ...
- 01-20-2008 #1Just Joined!
- Join Date
- Jul 2006
- Posts
- 60
: command not found in the first bash script
Write the fist hello.sh bash script as follows:
--------------------------------
# hello.sh
# This is my first shell script
printf "Hello! Bash is wonderful."
exit 0
--------------------------------
# bash hello.sh
: command not found
When I ran this script, I got a command not found error in the shell, what am I doing wrong here? Note if I delete the empty line, I got a different error.
# bash hello.sh
: numeric argument required
Also if I delete the "exit 0", I got nothing on the output.
# bash hello.sh
#
Need help on this, Thanks
Jiafan
- 01-20-2008 #2
Try using echo instead of printf e.g.
Code:#!/bin/bash #This is my first shell script echo "Hello! Bash is wonderful." exit 0
- 01-20-2008 #3
I'm thinking there might be invisible garbage in that script.
What editor are you using to write it? In other words, what program are you running at the moment you're actually typing the content of the script?--
Bill
Old age and treachery will overcome youth and skill.
- 01-20-2008 #4Just Joined!
- Join Date
- Jul 2006
- Posts
- 60
Actually you are right. I used editplus in Windows and copied it to a linux box. When I use the vi in Linux, this script works fine. Problem solved.
Thanks for giving me the hint.
Jiafan
- 01-21-2008 #5
For a bit more information: Linux (and indeed, all Unices, including Mac OS X) uses the LF character exclusively to represent newlines. Windows uses the sequence CRLF to represent newlines. As a result, when a file is written in Windows, it has CRs scattered everywhere throughout it. Many Linux editors will display the file properly anyway, which is good for many people, but for scripters / programmers, it is obviously a problem.
You can use the utility dos2unix (or for the other direction, unix2dos) to normalize all newlines in a text file.DISTRO=Arch
Registered Linux User #388732
- 01-21-2008 #6
That won't necessarily fix everything, and I suspect it wasn't enough here. Some "editors" in Windows don't store the data as pure text with CRLF line endings; they store additional formatting data. In that case, dos2unix (or, on my Slackware system, fromdos) won't be enough.
--
Bill
Old age and treachery will overcome youth and skill.
- 01-21-2008 #7
I just went to the editplus web page, and my guess is that they do not insert additional formatting data into the text; the only unwelcome addition would be the CR before each LF, as Cabhan suggests.
Yet, the error messages that JiafanZhou was getting suggest to me that something else was going on. I suspect that there was some other editor involved somehow. It's a mystery, but I'm happy that JiafanZhou's problem is solved and he can move on.--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote