Just started using UNIX, im at the basics and my scripts broken.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Just started using UNIX, im at the basics and my scripts broken.
# 1  
Old 11-08-2012
Just started using UNIX, im at the basics and my scripts broken.

Code:
echo "Hi $username, guess what my favourite colour is!"
count=0
while [[ $count -ne 1 ]] 
    do
                read colour
        if ["$colour" -eq "forget it"]
        then
            $count=1
            echo "See ya later!"
        elif ["$colour" -eq "watermelon"]
        then
            $count=1
            echo "You guessed correctly! Great job!"
        fi
        echo "try again or write forget it to give up"
done


Heres the script for a guessing game, for some reason it reads $colour as a literal when i pass it through the while loop and gives me errors like:

(if i passed in red for $colour)

[red: command not found

Why is it doing this???!

Moderator's Comments:
Mod Comment Please use code tags next time for your code and data.
# 2  
Old 11-08-2012
try using "count=1" not "$count=1". Also, include spaces around square brackets.
This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 11-08-2012
Insert a space after the opening bracket [ and before the closing bracket ].
This User Gave Thanks to radoulov For This Post:
# 4  
Old 11-08-2012
Didn't work, now its giving me this error when i pass in red

Code:
[: red: integer expression expected

# 5  
Old 11-08-2012
eq is for numeric comparison, use = instead:
Code:
[ "$colour" = "forget it" ] ...

This User Gave Thanks to radoulov For This Post:
# 6  
Old 11-08-2012
Replace -eq with = for string comparison.
This User Gave Thanks to Yoda For This Post:
# 7  
Old 11-08-2012
Awesome! thanks a lot!

All fixed!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX Basics about shell and editors and default settings

Hi all, I have 3-4 years of experience working on unix environment. I am not a beginner, but unix is not my primary skill set. I am very good at awk programming and doing many of my tasks very well, really very weak on basics. I moved to a new job recently and the settings there are driving me... (5 Replies)
Discussion started by: ysvsr1
5 Replies

2. Shell Programming and Scripting

How to get cron (scripts in crontab) started?

Hi, I have a query related to UNIX Crontab scripts - Issue: Server space on the db server got 100% full as a result of which the cron scripts did not run. The space utilization issue got resolved in the afternoon. The crons scheduled for a time post the resolution caught up. However the... (1 Reply)
Discussion started by: qwerty000
1 Replies

3. UNIX for Dummies Questions & Answers

UNIX basics

Hi, I am new to Unix. can you explain in brief with examples what is variable, what is argument and what is parameter? i searched a lot on other forums but not able to find a appropriate answer. thanks in advance!! (3 Replies)
Discussion started by: 21laps
3 Replies

4. UNIX for Dummies Questions & Answers

UNIX Basics

Hello, 1) I am trying to get involved in UNIX for educational purposes so I have installed the latest Ubuntu edition 12.04. Do you know another package that I could use it instead for educational purposes? 2)What is the difference between "~$" and "/$" (it comes with cd / and cd ~) .The... (1 Reply)
Discussion started by: Iwn
1 Replies

5. Shell Programming and Scripting

Need inputs on UNIX script basics

Hi UNIX Gurus, I have a SQL utility which fires DML statements against DB2 tables. Logic is to identify DML statements, put it into a file ($dml) and execute the job. DML file can have more than 1 DML statements....but all of 1 type at a time.....either all UPDATE or all DELETE. Job first... (2 Replies)
Discussion started by: ustechie
2 Replies

6. AIX

UNIX/AIX Performance Tuning = some basics please

Hi all, From Googling, I found that the basics used for troubleshooting UNIX/AIX performance issues are commands like vmstat, iostat and sar. I believe these are generic commands regardless of what UNIX flavour is in used, only difference being is the format of the output. In a real case... (2 Replies)
Discussion started by: newbie_01
2 Replies

7. Shell Programming and Scripting

Scripts and basics

Hi, I have a script which I need to modify the date "01/10/2008" and "31/10/2008" every month before running the report. Can I have some script to take the date automatically from the cal option. Hope it makes sense. Thanks in advance. (1 Reply)
Discussion started by: Jayanthsec
1 Replies

8. UNIX for Advanced & Expert Users

kill scripts which are started using nohup

i have scipt which is calling some other scripts and some built-in utilities like SED, find etc.. i started this script using nohup (e.g: nohup scriptname &) now i want to kill this script and all the child processes of this script. the problem is, process id of child processes are... (4 Replies)
Discussion started by: gfhgfnhhn
4 Replies

9. UNIX for Dummies Questions & Answers

Unix Basics

Hey, you said this forum was for Dummies, so don't blame me for the following! :D My whole "web building" life, I've had my sites hosted in one for or another. Lately, I've gotten into PHP and MySQL and, of course, those are also hosted for me. But lately, I've been thinking of using PHP and... (2 Replies)
Discussion started by: cap97
2 Replies

10. UNIX for Dummies Questions & Answers

UNIX Basics

I want to learn UNIX, but I have a few questions. If anybody could help me out I'd greatly appreciate it. First, I've decided I'm going to use Red Hat Linux and I've been told the only difference between 7.2 and the Professional (besides the price), is the tech support that you'll receive. Is... (2 Replies)
Discussion started by: paulSF
2 Replies
Login or Register to Ask a Question