Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Bourne Shell - OR operator correct usage

Posted on 2011-02-17
Medium Priority
297 Views
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 `]'

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?"
if [ \$answer = "y" ]
then
echo yes
elif [ \$answer = "Y" ]
then
echo yes
elif [ \$answer = "N" | "n" ]
then
echo no
else
echo BOO
fi
``````
0
Question by:nocturn4l
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 84

Accepted Solution

ozo earned 2000 total points
ID: 34914017
0

LVL 84

Expert Comment

ID: 34914019
see
man test
0

Author Closing Comment

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

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

## Featured Post

Question has a verified solution.

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

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Utilizing an array to gracefully append to a list of EmailAddresses
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
###### Suggested Courses
Course of the Month10 days, 3 hours left to enroll