Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shell Scripts - easy one

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
0
0
DE
Hi folks,

I must admit I'm not much of a scripter so this is quite a basic question:

I'm trying to write as script that sends out an e-mail as soon as a certain variable "fw" becomes smaller than 2

I tried out something like that:

...
if [ $fw < 2 ]
then ...

and also

if [ "$fw" < "2" ]
then

but the system always tries to create a file called "$fw" and to write 2 into it ... What's wrong here ?
How do I correct the problem ?

Thanks in advance !

Regards,
Thomas
 
Actualy:

Since it's it an arithmetic comparisson,then the best will be (assuming it's a ksh) :

if (( $fw < 2 )) ;then

"<" was writing to a file because it only does the comparrison while in the arithmetic context - "(( ))" brackets in ksh.



&quot;Long live king Moshiach !&quot;
 
you could also declare the var as an integer and use [[]]

integer fw=0

if [[ $fw < 2 ]];then
echo "Less than 2"
fi
 
you might also write it as ${fw}

the braces explicitly mark fw as a variable - I never write scripts without them anymore
 
No, the $ marks it as a variable, the {} mark the beginning/end of the varname. ie. you could have a variable name of me and me2. If you wanted me with the string 2 added to the end you'd have to do

${me}2

otherwise you'd get the value of me2 instead of me.

he,he,he
 
Hi folks,

thanks a lot for all your help !
It's been really useful and gave me a lot of ideas ...

Regards,
Thomas
 
Thomas,

Buy this book "Unix Shell Programming" by Hayden Books
ISBN 0-672-48448-X


It's a great place to start from.



--
| Mike Nixon
| Unix Admin
|
----------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top