Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
#!/bin/bash
for i in *.grb ;
do
str1= echo $i | awk '{print substr($1,24,2)+0 }'
echo $str1if [ "$str1" = "1" ];
then
uid="jan"
else
uid="not jan"
fiecho $uid
read pause
done
When I run the above script it , uid takes a value of not "not jan". However, echo $str1, does produce 1, before if test started.Can u help ?
Yacob

The echo $str1 command is not producing the 1 in your output. That command is echoing nothing (null). If you take out that echo, you will see that you still get the 1.
The following command:
str1= echo $i | awk '{print substr($1,24,2)+0 }'
is printing the 1. The first part of that command is assigning a null to str1. Then the echo|awk pipe is printing the 1.
Change that command to this:
str1=$(echo $i | awk '{print substr($1,24,2)+0 }')
Now your str1 variable will be loaded.
Another thing to keep in mind is that the = operator is for comparing strings, while the -eq operator is best for comparing numerics. For example, 1 and 01 will not compare equal using the = operator, but would compare equal using the -eq operator.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |