LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-15-2009, 11:44 AM   #1
GerardM
LQ Newbie
 
Registered: Oct 2006
Posts: 6

Rep: Reputation: 0
two comparisons


monkey="Chimpancee"
nut="Walnut"

if [ ${monkey} == "Chimpancee" ] -a [ ${nut} == "Walnut" ]
then
echo $monkey $Walnut
else
echo this is not good
fi

I get "[: too many arguments"

I do not understand it.. what I am looking for is how to do an and and how to do an or.
Thanks,
GerardM
 
Old 06-15-2009, 12:02 PM   #2
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 69
Code:
#!/usr/bin/env bash

MONKEY="Chimpanzee"
NUT="Walnut"

if [ "$MONKEY" == "Chimpanzee" ] && [ "$NUT" == "Walnut" ]; then
    echo $MONKEY $NUT
else
    echo "This is not good"
fi
Works for me
 
Old 06-15-2009, 12:04 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Code:
#!/bin/bash
monkey="Chimpancee"
nut="Walnut"

if [ ${monkey} == "Chimpancee"  -a  ${nut} == "Walnut" ]
then
  echo $monkey $nut
else
  echo this is not good
fi
 
Old 06-15-2009, 01:27 PM   #4
GerardM
LQ Newbie
 
Registered: Oct 2006
Posts: 6

Original Poster
Rep: Reputation: 0
so why does this give me an error message ?

if [ ${#} -lt 3 ] || [ ${ParmRevison} == "latest" ]

gives me
./Update.sh: line 33: [: ==: unary operator expected

the value for # is three and the value for ParmRevision is 51846

Thanks,
GerardM
 
Old 06-15-2009, 02:18 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Try
Code:
if [ ${#} -lt 3 ] || [ "${ParmRevison}" == "latest" ]
You're comparing apples and potatos up there (integer != string).
 
Old 06-15-2009, 02:28 PM   #6
GerardM
LQ Newbie
 
Registered: Oct 2006
Posts: 6

Original Poster
Rep: Reputation: 0
Thanks

Hoi,
This indeed makes the difference. The problem that I have is that this is not intuitive at all. As I do not understand where this is coming from, I spend an extreme amount of time on such niggardly bits.
Thanks,
GerardM
 
Old 06-15-2009, 08:41 PM   #7
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,295

Rep: Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358
You might find these useful:
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
string comparisons ricmon Programming 18 06-12-2007 10:31 AM
CPU comparisons lothario Linux - Hardware 2 12-11-2006 08:25 PM
Discuss: Performance Comparisons confused_bof Linux - General 4 12-22-2005 03:40 PM
Collecting TCO and other comparisons ggreaves General 1 02-02-2005 10:35 AM
Firewall Comparisons Please floppywhopper Linux - Security 11 10-02-2004 07:42 PM


All times are GMT -5. The time now is 12:14 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration