Computing.Net > Forums > Unix > simple srcipt

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

simple srcipt

Reply to Message Icon

Name: yacob
Date: March 18, 2008 at 12:34:30 Pacific
OS: Unix
CPU/Ram: 1Gb
Comment:

#!/bin/bash

for i in *.grb ;
do
str1= echo $i | awk '{print substr($1,24,2)+0 }'


echo $str1

if [ "$str1" = "1" ];
then
uid="jan"
else
uid="not jan"
fi

echo $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



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: March 18, 2008 at 15:37:29 Pacific
Reply:

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.


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: simple srcipt

A simple script for creating a link www.computing.net/answers/unix/a-simple-script-for-creating-a-link/6981.html

simple command script? www.computing.net/answers/unix/simple-command-script/2755.html

Help with Simple File Reading to Va www.computing.net/answers/unix/help-with-simple-file-reading-to-va/3777.html