multiple if conditions and EOF in a shell script

Thread Tools Search this Thread
# 1  
multiple if conditions and EOF in a shell script

I want to create an IF condition with multiple condition, in the statement below I want to add OR EOF, can any one please advise how to do.
if [ ${array[5]} !=  $sample ] && [ $c -eq 1 ]; then

echo .....


Moderator's Comments:
Mod Comment code tags please

Last edited by jim mcnamara; 04-13-2012 at 07:15 PM.. Reason: code tags
# 2  
if [[ "${array[5]}" !=  "$sample"  &&  $c -eq 1 ]]; then
  # do stuff here

use [[ and ]]

always put quotes around string variables or empty variables can generate errors that stop the script.

EOF: this is sort of the standard way to read file in straight shell and write the output to a file

while [[  read variable_name   &&   $farkle="something"  ]]
  # stuff goes here
  echo "something you want to see in the output file"

done < /path/to/inputfile   >  /path/to/outputfile

you can also exit a loop early with the break keyword

Last edited by jim mcnamara; 04-13-2012 at 07:45 PM.. Reason: forgot EOF

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #475
Difficulty: Medium
A Yottabyte (YB) equals 1,208,925,819,614,629,174,706,176 bytes.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use SQL Hard Code Conditions in UNIX Shell Script?

Hi All, I am trying to place one SQL query in Shell Script with Where Condition as Status='1' But after running the the script it is returning error as SQL0206N "1" is not valid in the context where it is used. SQLSTATE=42703 The query is working fine in Data Base. Please suggest... (1 Reply)
Discussion started by: sumanmca2006
1 Replies

2. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file based on certain conditions

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 5 columns having values say column 1,column 2.....column 5 as below along with their valuesm.... (1 Reply)
Discussion started by: Vivekit82
1 Replies

3. Shell Programming and Scripting

Shell script executing both the conditions.

I have written this script. This is used for creating a backup folder. #!/bin/sh #set -x . /home/.profile usage="Usage is $0" usage="$usage " # Use the getopt utility to set up the command line flags. set -- `/usr/bin/getopt b: $*` # Process individual command line arguments while ;... (1 Reply)
Discussion started by: arijitsaha
1 Replies

4. Shell Programming and Scripting

Help With Expect Script IF with Multiple Conditions

I am needing to include some if statements within an expect script. These will need to have two conditions under an AND join. Upon a successful IF condition I want to set multiple variables. I have tried a lot of variations of the below statement with no success. I have also searched the WEB... (2 Replies)
Discussion started by: Slagathor
2 Replies

5. UNIX for Dummies Questions & Answers

If + multiple conditions

Hello Unix-Forums! It has been a long time since my last post, but finally I've got a new question: I know in case you can use multiple patterns by case $var in a|b|c|ab) and so on. But how would I place an OR between if ] then ... if ] then ... I want to execute the "..." if... (3 Replies)
Discussion started by: intelinside
3 Replies

6. Shell Programming and Scripting

Oracle Shell script | here document `EOF' unclosed

Hi folks I m creating script which is give me below error. $ ./function.ksh ./function.ksh: here document `EOF' unclosed Inside the script is #!/bin/ksh export ORACLE_SID=OECDV1 export ORACLE_HOME=/u01/app/oracle/product/10.2.0 export PATH=$ORACLE_HOME/bin:$PATH echo "sql is... (3 Replies)
Discussion started by: tapia
3 Replies

7. Shell Programming and Scripting

Help regarding multiple conditions

Hi All, I am new to shell scripting. Can any one say what is wrong in this if statement, that uses multiple conditions if then *************** else if ( -z $pcs && "$night_time_calc" > "$night_time" ) then ******************************** ... (4 Replies)
Discussion started by: ssenthilkumar
4 Replies

8. Shell Programming and Scripting

How to Use Multiple if Conditions in Shell script

if -o ] then echo "Expected valid value" The above multiple if condition is NOT working in my script. I am getting the error as '-a' not expected. Can anyone help with the syntax for this? (5 Replies)
Discussion started by: dinesh1985
5 Replies

9. Shell Programming and Scripting

multiple if conditions

Guys, Im trying to have a script that evaluates multiple conditions : if then echo "host $1" else if then echo "host $1" else echo $1 not valid exit 1 fi when I do ./ brazil1 I get: (4 Replies)
Discussion started by: bashshadow1979
4 Replies

10. Shell Programming and Scripting

Check EOF in shell script

Hi, I need to check whether one file has EOF or not. There's one daemon in our system, which will pick the files FTPed to us. However, sometimes the daemon picks the file before FTP is finished. So I'm planning to add some checking of EOF on the FTPed files in the shell script. Could... (8 Replies)
Discussion started by: ideazhcy
8 Replies

Featured Tech Videos