The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with For Statements lexydoll87 UNIX for Dummies Questions & Answers 22 05-01-2009 01:58 AM
HELP!! if statements trob Shell Programming and Scripting 1 04-01-2009 03:24 PM
Please help on IF statements. filthymonk Shell Programming and Scripting 4 07-18-2007 06:59 AM
Else in If Statements chapmana UNIX for Dummies Questions & Answers 8 11-30-2006 08:07 AM
or statements? Blip Shell Programming and Scripting 1 01-19-2004 04:08 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 09-16-2009
Henry_Ford Henry_Ford is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 2
[SOLVED]IF-Statements not working

Dear Community,

I tried for over 4 days to figur this out.
I got a Shell-Code which contains some If-statements which are driving me crazy.
First of all the statements:

Code:
err=0;

echo "If-Test begins..."
if ! [[ "$err"==1 ]];then
echo "If NOT 0"
fi

if [[ "$err"!=0 ]];then
echo "If NOT (inside braces) 0"
fi

if [[ "$err"==1 ]];then
echo "If 0"
fi

if [[ "$err"==1 ]];then
echo "Using \" for 0"
fi

As "err" is 0 the last two statements shouldn't become true.
But when I am running the scrip the secon, third and fourth statement are returning "true" back, the first one not.
I really cannot get it... Where is my mistake?

Actually I tried every form of the comparison:

Code:
$err=0
$err==0
"$err"="0"
"$err"=="0"
'$err'='0'
 '$err'=='0'
$'err'='0'
$'err'=='0'

I also tried to mix the various format (eg. $err=="0") but really nothing is working.

---------- Post updated at 05:29 AM ---------- Previous update was at 05:22 AM ----------

Nervermind, just realisied that I have to put whitespaces between the argument and the variable...
Thanks anyway!

Last edited by Henry_Ford; 09-16-2009 at 07:30 AM.. Reason: [SOLVED]
 

Bookmarks

Tags
bash, if-statements, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0