Weird Problem???


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Weird Problem???
# 1  
Old 04-11-2003
Weird Problem???

I have a problem I don't understand... I am trying to declare a variable, and then output the results of that variable, couldn't be simpler
Code:
#!/bin/ksh

VAR='Oranges'
if [ ${VAR}='Lemons' ]
  then
  echo "Found Lemons"
elif [ ${VAR}='Oranges' ]
  then
  echo "Found Oranges"
fi

The output shouold clearly be "Found Oranges", but it outputs "Found Lemons", or whatever is first in the if statement, it's doing my head in, please somebody help!

added code tags for readability --oombera

Last edited by oombera; 02-17-2004 at 03:30 PM..
danhodges99
# 2  
Old 04-11-2003
just add some space on each side of the = comparison:


#!/bin/ksh

VAR='Oranges'
if [ ${VAR} = 'Lemons' ]
then
echo "Found Lemons"
elif [ ${VAR} = 'Oranges' ]
then
echo "Found Oranges"
fi
# 3  
Old 04-11-2003
edog is right, you need thoses spaces. For some insight to was happens without the spaces, see this post.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Weird awk problem

Hi, I have a simple awk script: BEGIN{} { $a=$2-$1; print $a } END{if(NR==0){ print "0" } } to which I provide the following input 2.9 14 22.2 27 (4 Replies)
Discussion started by: jamie_123
4 Replies

2. Shell Programming and Scripting

A very weird problem about getting a random string

Hi, guys Here is my script and it's an imaginary script to recast a string randomly. #!/bin/bash # scriptname: recast_string # purpose: recast a string randomly like this "abc123" --> "21a3cb" or "a31b2c" function recast() { local original_string=$1 local... (4 Replies)
Discussion started by: franksunnn
4 Replies

3. Programming

A weird problem with POSIX function

Hi all, Sorry for the title because I didn't find a proper name for it. My question is about POSIX functions, such as timer_create(), mq_open() and pthread_create(). void test_queue() { struct mq_attr attr; attr.mq_maxmsg = 10; attr.mq_msgsize = 64; mq_unlink("/my_test_queue");... (6 Replies)
Discussion started by: bus147
6 Replies

4. Shell Programming and Scripting

awk weird problem.

awk 'BEGIN{print 1.2.3.4}' 1.20.30.4 Can anyone explain why has extra "0" in the IP address? (3 Replies)
Discussion started by: newoz
3 Replies

5. UNIX for Dummies Questions & Answers

Weird problem with cp command on a Synology

Hi. First post, and Linux newbie, so maybe I'm missing something obvious: I have a Synology NAS that is run by a Linux distribution (which?). I have had an external hard drive connected to the NAS for making backups using Synology's backup application Time Backup. Time Backup is based on... (3 Replies)
Discussion started by: Pokersut
3 Replies

6. Infrastructure Monitoring

Weird dependency problem!

Hi, I want to install net-snmp-devel package but i have following dependecy problem. It's very odd, i don't get it. One of packages is depended on the other one, the other one is depended on the previous one as well. :S :S Could you help me please? Here are the steps: # ls -l total... (4 Replies)
Discussion started by: oduth
4 Replies

7. UNIX for Advanced & Expert Users

Really weird delete problem

Hi, I've Ubuntu 8.04, and it has some files that I just cannot delete. I've tried everything, inode, fsck etc. Here is what the ls -li outputs root@ubuntu:/home/luser/.local/share/Trash/files/junk# ls -l ls: cannot access TRUNK_: No such file or directory ls: cannot access 2006_output.mv:... (11 Replies)
Discussion started by: nitin
11 Replies

8. Shell Programming and Scripting

Weird date difference problem

I am trying to find the difference in days between 2 dates. I have to extract the 1st date from a filename, which i did using the awk command. I have to compare this date to today's date and if the difference is greater than 30 days, do something, else do something else. This is what i wrote... (22 Replies)
Discussion started by: meeraKh
22 Replies

9. Solaris

Weird crontab problem

Greetings To All! I am running Solaris 10 in a sparc environment. Here is the deal: In /var/spool/cron/crontabs, there is a cron user named "sys". If I do a crontab -l sys, it returns: # 0 * * * 0-6 /usr/lib/sa/sa1 # 20,40 8-17 * * 1-5 /usr/lib/sa/sa1 # 5 18 * * 1-5 /usr/lib/sa/sa2... (8 Replies)
Discussion started by: RobSand
8 Replies

10. UNIX for Advanced & Expert Users

weird problem with removing files

I have a few files on my system named: -rw------- -rw-r----- -rw-rw--w- -rwxrw-r-x (Yes, it's really the name of the file, not the access permissions, they're 0 bytes large and all created at the same date/time). I've no idea how they got there but I don't seem to be able to delete them... (2 Replies)
Discussion started by: rein
2 Replies
Login or Register to Ask a Question