Below is the list of files i've in my current directory:
ctc.SNAPSHOT-1.0.1-abc.gz
ctc.SNAPSHOT-2.0.1-bcd.gz
ApprovedList.A
ApprovedList.B
cat ApprovedList.A
BC
DEF
I want to pass 3 parameters to the script,but i guess the script is unable to read the variable : $num1
.
Below is my code:
#!/bin/bash
case "$#" in
0|1|2)
echo "Correct Usage: $0 A/B/C <rec_name>/ALL <version_number>."
exit 1
;;
esac
ops () {
echo $line
}
num1=$(for i in *gz; do num=$(echo $i|sed -E -n 's/ctc.*\-(.*)\-.*/\1/p'); echo $num; done)
while read -r line
do
case "$1" in
A|B|C)case "$2" in
$line|ALL)case "$3" in
$num1)ops;;
esac;;
esac;;
esac
done < /home/us3r/ApprovedList."$1"
When i execute the script, it gives no output.
Execution: ./script.sh A ALL 1.0.1
Expected output:
BC
DEF
I have tried the above code using multiple if
conditions and it's working, i just wanted to make my code more readable and compact ,so i thought of using case
statements.