I can't get what I'm doing wrong!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I can't get what I'm doing wrong!
# 8  
Old 07-17-2012
Please post the output from the three commands I requested in the newly numbered post #6 (the one before your most recent post).



Quote:
I made the script in the nano editor and saved as DOS
Doh!
# 9  
Old 07-17-2012
Quote:
Originally Posted by methyl
@Scott I think that most of it was in the deleted posts. It was Ubuntu Server the Shell was bash.

Where I left off after the mystery of an error on line 29 when there were not 29 lines in the script: I don't believe that your ./test.sh executed what you think it did.

Please post the output from:
Code:
wc -l test.sh        # Count the number of line in the script (parameter is "ell" not "one")

sed -n l test.sh     # Contents of the script making all control codes visible (parameter is "ell" not "one")

alias                # List of aliases - just in case test.sh is an alias

Outputs:
Code:
marius@ubuntuserver:~$ wc -l test.sh
7 test.sh

marius@ubuntuserver:~$ sed -n l test.sh
#/bin/bash\r$
echo "Test script"\r$
read cake\r$
if [ "$cake" == "1" ]\r$
then\r$
    echo "cake it is"\r$
fi\r$

marius@ubuntuserver:~$ alias
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

# 10  
Old 07-17-2012
In the output from sed -n l a line-feed character shows as a dollar sign and a carriage-return shows as \r.
The script is indeed in Microsoft MSDOS format not unix text file format. It has the two characters carriage-return line-feed at the end of every line instead of the unix standard line terminator which is the single character line-feed.

The MSDOS format makes the script impossible to process in bash and we get all sorts of funny error messages.
I don't know the nano editor myself but you need to save all text files (including Shell scripts) in unix format not MSDOS format. Or use a unix editor such as vi or vim. Many people use nano so it must be possible to get it to work.

Check your corrected script with sed -n l scriptname to make sure that the \r (carriage-return) characters have gone.

Good luck.

Last edited by methyl; 07-17-2012 at 10:49 PM..
This User Gave Thanks to methyl For This Post:
# 11  
Old 07-17-2012
I remote control my computer over SSH Atm, may that be the problem? (Just a taught)
# 12  
Old 07-17-2012
No. The problem is that you are saving text files in DOS format which is the wrong format for text files on unix/Linux systems like yours.

The nano editor can save text files in three possible formats:

unix/Linux - Line terminator is line-feed. The one we want!
Microsoft MSDOS - Line terminator is two characters: carriage-return line-feed.
Apple MACOS (older) - Line terminator is carriage-return.

Last edited by methyl; 07-17-2012 at 10:46 PM.. Reason: layout and clarification
# 13  
Old 07-17-2012
PHP Some changes and a new error

Some changes and a new error! I am now using the VI editor, and the code is now
Code:
#/bin/bash
echo "Test script"
read cake
if [ $cake == "1" ]
then
echo "The Cake is a lie"
else
echo "The shit?"
fi

and it outputs:
Code:
Test script
1
test2.sh: 4: [: 1: unexpected operator
The shit?

# 14  
Old 07-17-2012
Very short memory?
Always put quotes round string variables:

Code:
#/bin/bash
echo "Test script"
read cake
if [ "$cake" == "1" ]
then
echo "The Cake is a lie"
else
echo "The shit?"
fi

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

2. UNIX for Advanced & Expert Users

What am I doing wrong here?

I am working on a simple login ID check shell script that should prompt for a user ID then check to see if this user is logged on. Trying to get the hang of this stuff so I am thinking of my own little projects. #! /bin/sh echo "please enter a user name" read user if user=$user then... (3 Replies)
Discussion started by: jsk319342
3 Replies

3. UNIX for Dummies Questions & Answers

What is wrong in here ???

]#PATH=/usr/bin:/etc:/bin:/boot/grub:/boot/grup/bin: /boot/solaris/bin:/sbin:/usr/openwin/bin:/usr/5bin://usr/X11/bin:/usr/apache/bin:/usr/apache2/bin:/usr/appserver/bin:... (9 Replies)
Discussion started by: microbot
9 Replies

4. Shell Programming and Scripting

what I m doing wrong?

when user select option 2 nothing happen.for testing purpose I put echo command but is not executing . basically when user prompt for option 2,I want to get list of database name from user separeted by space (TEST DEVL) and put into the file seprated by new line TEST DEVL after that stay on... (1 Reply)
Discussion started by: okreporthai
1 Replies

5. UNIX for Dummies Questions & Answers

what is wrong with this tr -d?

here is my command in bash shell on Mac OS X tiger: history | tr -d emacs here is what I get: hitory | grp "" | tr -d "" hitory | grp "" | tr -d """" hitory | grp "" | tr -d '' hitory | grp "" | tr -d '' hitory | grp "" | tr -d '' hitory | grp "" | tr -d... (3 Replies)
Discussion started by: cleansing_flame
3 Replies

6. UNIX for Dummies Questions & Answers

What am I doing wrong?

I really just mess around in UNIX, for the most part, when I want to get something done. I can usually piece things together by searching for brief how-to's on Google, but the syntax errors in my following .sh file are really confusing me. I've got lots of programming experience in other places, so... (7 Replies)
Discussion started by: demonpants
7 Replies

7. UNIX for Dummies Questions & Answers

what is wrong here

Hello, I have a simple script such as ----------------------------- #! /bin/sh YEAR=`date -u +%Y`; MONTH=`date -u +%m`; DAY=`date -u +%d`; DATE=$MONTH$DAY$YEAR LOGFILES=auditTrail-$DATE LOGMATCH=$LOGFILES\* ARGUM='' # find all files and write them to a file find . -name... (7 Replies)
Discussion started by: arushunter
7 Replies

8. Shell Programming and Scripting

Anything wrong with this

Does anyone see anything wrong with this. #getInfraFiles() #{ # cd Infra/$DAY # rm * # /usr/bin/ftp -i -n $LINE << cmd # user "$USER" "$PASSWD" # cd $INFRAPATH # binary # mget * # bye #} besides that its commented out (4 Replies)
Discussion started by: rcunn87
4 Replies

9. UNIX for Dummies Questions & Answers

Please tell me what do I do wrong here!

#!/usr/bin/csh # DAY=`date +%y%m%d` H=`date +%H` M=`date +%M` mailx -s "$H-Myfile" email@email.com</home/mydir/myfile Thanks! (4 Replies)
Discussion started by: bobo
4 Replies

10. UNIX for Advanced & Expert Users

What am I doing wrong

When I execute following shell script I am getting the following error syntax error at line 50 : `<<' unmatched What am I doing wrong :confused: Script begins here ---------------- MPAN_FILE=$1 exec 3<$MPAN_FILE ... (2 Replies)
Discussion started by: guptan
2 Replies
Login or Register to Ask a Question