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:
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:
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]
All of the tests in your post are for strings. while this may work I would suggest using the correct operators for numeric tests. -eq,-gt,-lt,-ne,-ge,-le. I also recommend indenting your code three spaces for readability.
ie:
Last edited by frank_rizzo; 09-16-2009 at 08:24 PM..
Reason: typo
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
It would help to know which shell you use.
In general the number of square brackets matters. There is rarely a reason to use "[[ condition ]]" when "[ test ]" would do.
Paraphrasing and decomplicating your code. I have removed surplus semi-colons, moved exclamation marks (meaning NOT), replaced string comparisons "=" with integer comparisons "-eq", and inserted spaces where required. The last two tests are identical, so I have removed the duplicate.
Enjoy.
Last edited by methyl; 09-16-2009 at 09:24 PM..
Reason: typo
Hi I am trying the following in my bash script which logs into my machine and runs a command. Trying to solve this using expect.
The first expect statement is hit and it enters the address "10.10.0.10" but when the second expect statement is hit it exits
#!/bin/bash
expect -c '
spawn... (2 Replies)
Hello. I am new here and new to scripting. I used to have a very basic script that worked for simple backup/restore of files. I have expanded it and well... I have ended up with a complete mess. It still backs up and restores but there is so many issues that stem from the many if statements I... (3 Replies)
I came across a bash script that outputs the forecast for the day and the max temperature but at the end of the day the max temperature disappears ($6) and I am left with "°C" after the forecast.
Here is the script:
#! /bin/bash
curl -s --connect-timeout 30... (7 Replies)
1. The problem statement, all variables and given/known data:
Two problems I need solving please. I created a script where the user types in 7 numbers as standard input and each one is then stored in an array. Now I need to perform the following calculations on those numbers:
1) Use a while... (11 Replies)
Hi
I am very new to Unix programming and shell scripting. I am trying t figure out how to write a little script that will output the number of directories. I can find the number of directories using ls -l | grep "^d" | wc -l I can not figure out how to do it so when I type the name... (8 Replies)
I am writing a script that does a search for a argument in a file and lists all like occurrences. The script verifies that it is a file and then runs another script that list the lines. My problem is that I need the script to accept a file or a directory and then go to that directory check all... (1 Reply)
I am kind of new in Unix and i have to make a menu. I want to put an if statement in the menu. you should enter the filename and it goes to that file. How do i do this? (1 Reply)
I had different problem scenarios with IF statement. Can any expert please enlighten me on the difference with these scenarios. Thank you.
1st Scenario:
testdate=`date +%Y%m`
test=`cat /var/log/database0.$testdate*.log | grep "Errors found during processing" | tail -10`
if
then
... (4 Replies)
Sorry to be a pain, but how does the else work in the if statements?
Ive been making scripts with if statements but i cant get the else statements working.
Can you help? (8 Replies)