Here is a sample script that shows a few ways to do what you're trying to do that work with both bash and ksh:
Code:
printf "Enter answer: "
while read answer
do if [ "$answer" = "y" ] || [ "$answer" = "Y" ]
then printf "true: %s\n" \
'if [ "$answer" = "y" ] || [ "$answer" = "Y" ]'
else printf "false: %s\n" \
'if [ "$answer" = "y" ] || [ "$answer" = "Y" ]'
fi
if [[ "$answer" == [yY] ]]
then printf "true: %s\n" \
'if [[ "$answer" == [yY] ]]'
else printf "false: %s\n" \
'if [[ "$answer" == [yY] ]]'
fi
if [[ "$answer" == [yY]* ]]
then printf "true: %s\n" \
'if [[ "$answer" == [yY]* ]]'
else printf "false: %s\n" \
'if [[ "$answer" == [yY]* ]]'
fi
case "$answer" in
([yY]) printf "match: case %s\n" '([yY])';;
([nN]) printf "match: case %s\n" '([nN])';;
(*) printf "no match: cases ([yY]) and ([nN])\n"
esac
case "$answer" in
([yY]*) printf "match: case %s\n" '([yY]*)';;
([nN]*) printf "match: case %s\n" '([nN]*)';;
(*) printf "no match: cases ([yY]*) and ([nN]*)\n"
esac
printf "Enter another answer: "
done
printf "\nDone.\n"
The [[ expr ]] tests are not available in a Bourne shell and are not required by the POSIX standards; the other forms are required by the POSIX standards and will also work with an old Bourne shell.
Last edited by Don Cragun; 12-30-2013 at 10:48 PM..
Reason: Fix typos: $aswer in a few places should have been $answer & missing "[" in printf arguments.
This User Gave Thanks to Don Cragun For This Post:
What awk command will test a string to determine if it is a valid file name?
With the following awk statement I isolate the lines from the inputfile that might contain a filename, then I attempt to test the possible filename which is always in $4 from each line. However it is not working at all... (4 Replies)
This is the code:
while test 1 -eq 1
do
read a
$a
if test $a = stop
then
break
fi
done
I read a command on every loop an execute it.
I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test.
For example echo hello.
Now the... (1 Reply)
I have a string like ab or abc of whatever length. But i want to know whether another string ( for example, abcfghijkl, OR a<space> bcfghijkl ab<space> cfghijkl OR a<space>bcfghijkl OR ab<space> c<space> fghijkl ) starts with ab or abc... space might existing on the longer string... If so, i... (1 Reply)
I want to compare two strings using awk dynamically without trimming the spaces and want to find the count of matching string.
Input Strings file:
File1 content (file1):
" a "
" a2 "
File2 content (file2):
" a "
" a "
" a2 "
" b2 "
" c2 "... (3 Replies)
Hi,
I have a Python unit test cases source code file which contains more than a hundred test case methods. In that, some of the test case methods already have prefix 'test' where as some of them do not have. Now, I need to add the string 'test' (case-sensitive) as a prefix to those of the... (5 Replies)
Hi All,
my requirement is first search the line and updated stg value with the user input value.
ws.rsp.url=https://rt930.rsp-stg.cb.info53.com/RSP/RAFT^M
stg is not fixed string it may varies.So i used the below command for it
rsp=`cat properties | grep ^ws.rsp.url= | awk -F"/"... (1 Reply)
Hi ! :)
I made this :
#!/bin/bash
rsa_dir="/etc/openvpn/easy-rsa/"
rsa_key_dir="/etc/openvpn/easy-rsa/keys/"
ccd_dir="/etc/openvpn/ccd/"
regex_special_char=''
cd $rsa_dir
while
read -p "Please can you enter the vpn's username : " username
] || ] || ] || ]
do
echo "Your entry... (10 Replies)
Discussion started by: Arnaudh78
10 Replies
LEARN ABOUT V7
arithmetic
ARITHMETIC(6) Games Manual ARITHMETIC(6)NAME
arithmetic - provide drill in number facts
SYNOPSIS
/usr/games/arithmetic [ +-x/ ] [ range ]
DESCRIPTION
Arithmetic types out simple arithmetic problems, and waits for an answer to be typed in. If the answer is correct, it types back "Right!",
and a new problem. If the answer is wrong, it replies "What?", and waits for another answer. Every twenty problems, it publishes statis-
tics on correctness and the time required to answer.
To quit the program, type an interrupt (delete).
The first optional argument determines the kind of problem to be generated; +-x/ respectively cause addition, subtraction, multiplication,
and division problems to be generated. One or more characters can be given; if more than one is given, the different types of problems
will be mixed in random order; default is +-
Range is a decimal number; all addends, subtrahends, differences, multiplicands, divisors, and quotients will be less than or equal to the
value of range. Default range is 10.
At the start, all numbers less than or equal to range are equally likely to appear. If the respondent makes a mistake, the numbers in the
problem which was missed become more likely to reappear.
As a matter of educational philosophy, the program will not give correct answers, since the learner should, in principle, be able to calcu-
late them. Thus the program is intended to provide drill for someone just past the first learning stage, not to teach number facts de
novo. For almost all users, the relevant statistic should be time per problem, not percent correct.
ARITHMETIC(6)