Solved

Bourne Shell - OR operator correct usage

Posted on 2011-02-17
4
284 Views
Last Modified: 2012-05-11
hi me again.. gonna be here all night unfortunately.. I seem to be not using the | operator correctly.. i'm hoping someone can help me out


if the user answers with a "y" or "Y" i want it to do something.... well what I wrote works.. but obviously I would like to learn the correct and simplified way of doing it.  I tried it with "n" and "N" but that gives me an error of

line 10: [: missing `]'
line 10: n: command not found



i tried "N"|"n" with no spaces

i also tried [ $answer = "N" ] | [ $answer = "n" ]

couldn't get either to work..
#!/bin/sh
echo "Are you OK?"
read answer
if [ $answer = "y" ]
then
echo yes
elif [ $answer = "Y" ]
then
echo yes
elif [ $answer = "N" | "n" ]
then
echo no
else
echo BOO
fi

Open in new window

0
Comment
Question by:nocturn4l
  • 2
4 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 34914017
if [ "$answer" = "N" -o "$answer" = "n" ]
0
 
LVL 84

Expert Comment

by:ozo
ID: 34914019
see
man test
0
 

Author Closing Comment

by:nocturn4l
ID: 34914028
thank you... I try not to ask on here unless I've tried several things.. i'm following a book right now and I guess I misread it.. the OR operator | is for arithmetic only i guess?

thanks for the suggestion on looking up "man test". will do that right now
0
 
LVL 48

Expert Comment

by:Tintin
ID: 34923016
The logical OR operator is || not |
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now