I'm trying to use regex in an if statement in a bash script, but I am getting different values.
The script:
#!/bin/bash
a="input2.txt"
paramCheck(){
while read -r line; do
d=( $line )
e=${d[@]:1}
for i in "$e"; do
if [ "$i" == $[st][0-9] ]; then
echo "$i"
fi
done
done < "$a"
}
echo `paramCheck`
The text file:
add $s1 $s2 $s3
sub $t0
sub $t1 $t0
addi $t1 $t0 $s5
The predicted results:
$s1 $s2 $s3 $t0 $t1 $t0 $t1 $t0 $s5
The actual result was: nothing printed out.