Errors in if conditions.....


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Errors in if conditions.....
# 1  
Old 12-17-2012
Errors in if conditions.....

Code:
Code:
#if [ "$var" -ne 1 -a "$var" -ne 2 -a "$var" -ne 3 -a "$var" -ne 4 -a "$var" != "2 Then 1" -a "$var" != "3 Then 1" -a "$var" != "4 Then 1" ]
if [ "$var" -ne 1 -a "$var" -ne 2 -a "$var" -ne 3 -a "$var" -ne 4 -a "$var" != "2 Then 1" -a "$var" != "3 Then 1" -a "$var" != "4 Then 1" ]
then
echo $varNO >> AgriN.csv
fi
done < data


The above script throws error such as integer expression expected. How do i rectify that??
# 2  
Old 12-17-2012
You could do a number of things.
  • Validate your input to ensure it only contains numbers
  • Change from numeric to string operators
  • Throw the error away and ignore it
# 3  
Old 12-17-2012
i did that scott.... but no luck....
# 4  
Old 12-17-2012
You did which bit?
Code:
[scott@web1] /home/scott/scripts $ cat myScript
echo "Output from first loop..."
while read var; do
  if [ "$var" -ne 1 -a "$var" -ne 2 -a "$var" -ne 3 -a "$var" -ne 4 \
      -a "$var" != "2 Then 1" -a "$var" != "3 Then 1" -a "$var" != "4 Then 1" ]; then
    echo Blah
  fi
done < file1
echo
echo "Output from second loop..."
while read var; do
  if [ "$var" != 1 -a "$var" != 2 -a "$var" != 3 -a "$var" != 4 \
    -a "$var" != "2 Then 1" -a "$var" != "3 Then 1" -a "$var" != "4 Then 1" ]; then
    echo Blah
  fi
done < file1
echo "End."
[scott@web1] /home/scott/scripts $ ./myScript
Output from first loop...
./myScript[3]: ia: 0403-009 The specified number is not valid for this command.
Blah
 
Output from second loop...
Blah
Blah
End.

You can't use numeric operators in any case, since you expect $var to be either a number or a string, so you should always treat it like a string.
This User Gave Thanks to Scott For This Post:
# 5  
Old 12-17-2012
thank you Smilie Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Conditions in if

I'm using the below one.. #!/bin/ksh File=$3 if ; then echo "Script" elif ] ;then echo "Passed k or f option" else "Please check the Input passed" fi Command line argument is "k" or -f and file is exist then... (3 Replies)
Discussion started by: Roozo
3 Replies

2. Shell Programming and Scripting

Errors in if conditions with to many OR conditions

Hi ALL I have a script where in i need to check for several values in if conditons but when i execute the script it throws error such as "TOO MANY ARGUMENTS" if then msg="BM VAR Issue :: bmaRequestVAR=$bmaRequestVAR , nltBMVAR=$nltBMVAR , bmaResponseVAR=$bmaResponseVAR ,... (10 Replies)
Discussion started by: nikhil jain
10 Replies

3. Shell Programming and Scripting

If conditions need

Dear Expert, Below code is for to take the backup of database by daily time stamp. I need vital help to make my script automatic sending me email if it sucess or fail. echo on @REM Seamonkey's quick date batch (MMDDYYYY format) @REM Setups %date variable @REM First parses month, day, and... (6 Replies)
Discussion started by: Alone
6 Replies

4. Shell Programming and Scripting

IF OR with two conditions

I have this IF working fine, testing if a char is a digit: if ; then _VALUE=$_VALUE$_CHAR else _ISDIGIT="false" fi Then I add a second condition to test if the char is either a digit or a * if ]; then _VALUE=$_VALUE$_CHAR ... (11 Replies)
Discussion started by: Flavius
11 Replies

5. Shell Programming and Scripting

While with three conditions

Currently this is what I am trying while || && ]; do I want to continue if the first condition or both the second and third are true but I am getting a too many arguments error. Can someone help me out? (5 Replies)
Discussion started by: whdr02
5 Replies

6. Shell Programming and Scripting

conditions

./script 89 The script will extract the last digit of the input parameter. example, that is 4. This will be compared to the last digit of the current day of the month ( like day 14; that is 4). A message will displayed on the screen indicating if the digits are the same or not. (1 Reply)
Discussion started by: singh is king
1 Replies

7. UNIX for Dummies Questions & Answers

2 or more if conditions

Hello, I have a file as follows: col no:1 2 3 4 5 6 7 8 9 10 11 a 4 226 226 ch:95024048-95027592, 1y224 of 3545 223 224 ident b 53 235 235 ch:148398-148401255, 1y184 of 3187 180 186 ident awk... (3 Replies)
Discussion started by: dr_sabz
3 Replies

8. UNIX for Dummies Questions & Answers

Major OS errors/Bash errors help!!!!

Hi all, dummy here.... I have major errors on entering the shell. On login I get: -bash: dircolors: command not found -bash: tr: command not found -bash: fgrep: command not found -bash: grep: command not found -bash: grep: command not found -bash: id: command not found -bash: [: =: unary... (12 Replies)
Discussion started by: wcmmlynn
12 Replies

9. AIX

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (2 Replies)
Discussion started by: mcastill66
2 Replies

10. UNIX for Advanced & Expert Users

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (0 Replies)
Discussion started by: mcastill66
0 Replies
Login or Register to Ask a Question