You're missing a semi-colon in where you're setting $row, $col, and $fi.
case $opts in
r) row=$OPTARG echo "-r was triggered, Parameter: $OPTARG";;
c) col=$OPTARG echo "-c was triggered, Parameter: $OPTARG";;
f) fi=$OPTARG echo "-f was triggered, Parameter: $OPTARG";;
\?) printf "Kullanım: %s -r değer -c değer dosya adresi\n" $0
exit 2;;
esac
Should be (semi-colon before the echo
):
case $opts in
r) row=$OPTARG ; echo "-r was triggered, Parameter: $OPTARG";;
c) col=$OPTARG ; echo "-c was triggered, Parameter: $OPTARG";;
f) fi=$OPTARG ; echo "-f was triggered, Parameter: $OPTARG";;
\?) printf "Kullanım: %s -r değer -c değer dosya adresi\n" $0
exit 2;;
esac
Without those semi-colons, your commands are not being run as you would expect, as you can see looking at the output of bash -x, and examine the lines with -gt:
bash-[576]$ bash -x foo.bash -r 3 -c 3 -f foo
+ str1='Hata: '
+ str2='. satır '
+ str3='. sütun yok'
+ getopts r:c:f: opts
+ case $opts in
+ row=3
+ echo '-r was triggered, Parameter: 3'
-r was triggered, Parameter: 3
+ getopts r:c:f: opts
+ case $opts in
+ col=3
+ echo '-c was triggered, Parameter: 3'
-c was triggered, Parameter: 3
+ getopts r:c:f: opts
+ case $opts in
+ fi=foo
+ echo '-f was triggered, Parameter: foo'
-f was triggered, Parameter: foo
+ getopts r:c:f: opts
+ '[' -gt 3 ']'
foo.bash: line 18: [: -gt: unary operator expected
+ '[' -gt 3 ']'
foo.bash: line 20: [: -gt: unary operator expected
+ awk 'NR==r{print $c}' r= c=
With the semi-colons:
bash-[574]$ bash -x foo.bash -r 3 -c 3 -f foo
+ str1='Hata: '
+ str2='. satır '
+ str3='. sütun yok'
+ getopts r:c:f: opts
+ case $opts in
+ row=3
+ echo '-r was triggered, Parameter: 3'
-r was triggered, Parameter: 3
+ getopts r:c:f: opts
+ case $opts in
+ col=3
+ echo '-c was triggered, Parameter: 3'
-c was triggered, Parameter: 3
+ getopts r:c:f: opts
+ case $opts in
+ fi=foo
+ echo '-f was triggered, Parameter: foo'
-f was triggered, Parameter: foo
+ getopts r:c:f: opts
+ '[' 3 -gt 3 ']'
+ '[' 3 -gt 3 ']'
+ awk 'NR==r{print $c}' r=3 c=3 foo
Again, look at the lines with -gt. So your variable settings of $row, $col, and $fi are not propagating without the ;
.