Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

Bourne Shell - OR operator correct usage

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
nocturn4l
Asked:
nocturn4l
  • 2
1 Solution
 
ozoCommented:
if [ "$answer" = "N" -o "$answer" = "n" ]
0
 
ozoCommented:
see
man test
0
 
nocturn4lAuthor Commented:
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
 
TintinCommented:
The logical OR operator is || not |
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now