Problem with case in bash
Hello everyone,
i am fairly new to shell scripting so please bear with me.
The following script is supposed to read words from a file and depending on the word print different things.
However it always prints the default value.
It also refuses to work completely if the first line in 'numbers.txt' is not a blank line.
I would be grateful for any hints whatsoever.
script
#!/bin/bash
file="numbers.txt"
while read line
do
operator=`awk '{print $1}' $line`
case $operator in
"divide") echo "/";;
"multiply") echo "x";;
"add") echo "+";;
"subtract") echo "-";;
*) echo "default";;
esac
done < "$file"
numbers.txt (the first line is a blank!)
divide
multiply
add
subtract
Related Article: Condition in Case Statement
is a Shell Scripting discussion thread by prakash2813 that has 1 reply and was last updated 8 months ago.
replic
Junior Poster in Training
52 posts since Nov 2008
Reputation Points: 27
Solved Threads: 6
Skill Endorsements: 0
$
divide$
multiply$
add$
subtract$
replic
Junior Poster in Training
52 posts since Nov 2008
Reputation Points: 27
Solved Threads: 6
Skill Endorsements: 0
replic
Junior Poster in Training
52 posts since Nov 2008
Reputation Points: 27
Solved Threads: 6
Skill Endorsements: 0
Question Answered as of 3 Months Ago by
Watael
and
ravi89