Two condition in if statement

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Two condition in if statement
# 1  
Old 09-09-2013
Two condition in if statement


I need to put two condition in if statement, but it is not working. Please suggest.

if [ $var -le 10 && $var -ne 0 ]

---------- Post updated at 07:05 AM ---------- Previous update was at 06:55 AM ----------

Also when i put below command in script it is not running, but manually it is running

#folder=`ll /FOLDER/ | wc -l`

#echo $folder

But when put in script it gives error.

]# sh line 1: ll: command not found

# 2  
Old 09-09-2013
Try this

akshay@Lenovo-E49:~$ var=4
akshay@Lenovo-E49:~$ if [[ $var -le 10 && $var -ne 0 ]];then echo "Yes";fi

stop using grave accents it's not good way

akshay@Lenovo-E49:~$ cat

FOLDER=$(ls -alF | wc -l)
echo $FOLDER

akshay@Lenovo-E49:~$ sh 

checkout your .bashrc

alias ll='ls -alF'

# 3  
Old 09-09-2013
if [ $var -le 10 ] && [ $var -ne 0 ]

# 4  
Old 09-09-2013
You should export the folder variable in order to make it available in subshells.
# 5  
Old 09-09-2013
There are two kinds of test, with different syntax.
Two [test] commands or two [[test]] compounds; the logical AND is handled by the shell:
if [ $var -le 10 ] && [ $var -ne 0 ]
if [[ $var -le 10 ]] && [ $var -ne 0 ]

The logical AND is handled by the [test] command or the [[test]] compound:
if [ $var -le 10 -a $var -ne 0 ]
if [[ $var -le 10 && $var -ne 0 ]]

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. Shell Programming and Scripting

If statement with unmatched condition

Hi Gurus, I'm facing some issues with multiple conditions in my if statement. if (!($InputLine=~/^Date/)) && (!($fields eq "VEN")) { Above is the line troughing some syntax errors. I am trying to avoid the below creteria lines to process in my logic. Records starting with... (4 Replies)
Discussion started by: hi.villinda
4 Replies

3. Shell Programming and Scripting

If condition return 0 even when it fails to satisfy te condition

HI My doubt may be basic one but I need to get it clarified.. When i use "if" condition that checks for many AND, OR logical conditions like if ]; then return 0 fi Even the if condition fails it returns as zero.. Any clue.. But if i add else condition like if ]; ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

4. Shell Programming and Scripting

If condition and for loop within sed statement

Hi, I tried to go through a lot of online material but could not find concrete solution. My issues is like this : I've got a input file like this : <a> <startDate>19700101000000</startDate> <endDate>20300101000000</endDate> </a> ... (12 Replies)
Discussion started by: Shaishav Shah
12 Replies

5. UNIX for Dummies Questions & Answers

LINUX Multiple condition in IF Statement - Pls help

Hi All, I am trying to put multiple conditions in an IF Statement (using $$). the Linux script somehow doesnt like it. The logic I am trying to implement is as follows, 1. I will first search for DateFile.txt 2. If it exists & there is a P_BUS_DATE value in it, then assign the date value... (5 Replies)
Discussion started by: dsfreddie
5 Replies

6. Shell Programming and Scripting

redirect stdout echo command in condition A run in condition B

hi, I have some problems in my simple script about the redirect echo stdout command inside a condition. Why is the echo command inside the elif still execute in the else command Here are my simple script After check on the two diff output the echo stdout redirect is present in two diff... (3 Replies)
Discussion started by: jao_madn
3 Replies

7. HP-UX

Difference between [condition] and [[condition]] and ((condition)) when used with if condition

Executed the following if conditions .. and got different results . only (( )) gave correct o/p with all scenarios . Can anybody please let me know what is the difference between and ] and ((condition)) when used with if condition. And why each condition gave different result. 1.... (2 Replies)
Discussion started by: soumyabubun
2 Replies

8. Shell Programming and Scripting

An issue with condition statement in shell script

Hello forum members. please go through the below mentioned issue and let me know the right solution. I have to write a script which runs another script .the executable script take input iam writing the the script below . Sample Code:Begins #! /bin/ksh echo " enter... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

9. Shell Programming and Scripting

Condition statement in perl

#!/usr/bin/perl $output1 = "/home/log.txt" $output2 = "/home/grep.txt" #Statement1 creates an output file called log.txt. #Statement2 greps a line from log.txt and store the result in grep.txt I want to create a condition where if the file grep.txt is empty repeat process. Thanks. (1 Reply)
Discussion started by: sureshcisco
1 Replies

10. UNIX for Dummies Questions & Answers

Multiple Condition If statement

Hi, I would like to create an IF statement where if a variable is equal to at least one of 2 (or more) values then the script proceeds. For example: TEST_VAR=2 if ; then echo success! else echo failure fi I understand that the above syntax is wrong but I feel it must be close. Any... (1 Reply)
Discussion started by: msb65
1 Replies
Login or Register to Ask a Question