Sponsored Content
Top Forums Shell Programming and Scripting multiple conditions in if statements Post 20513 by Jimbo on Sunday 28th of April 2002 09:42:39 AM
Old 04-28-2002
On assignments to a variable, do x= instead of $x= .

When you use a mixture of -o and -a, you might have to control precedence. In the following, the first line would test true because -o has precedence:
if [ a = a -o b = b -a c = C ]
But add parentheses (you would need to backslash these) and it would now test false:
if [ ( a = a -o b = b ) -a c = C ]

Also, when checking for several values, a case statement makes for nice clean code, and even more handy when each value will result in a different action:
Code:
case $x in
 +|-|/|%) x=$vr1;;
       *) print "You have entered an invalid option."
          exit 1;;
esac

Jimbo
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

multiple 'if' statements out of array

I want to do multiple comparisons on a series of numbers from an array: I send the numbers in file1 through want to print out some info from file2 based on some conditions. The syntax just isn't correct??? awk ' NR==FNR{ a=$0 next ... (2 Replies)
Discussion started by: dcfargo
2 Replies

2. Shell Programming and Scripting

if then statements with two conditions...?

Is it possible to setup two conditions for an if then statement in a pbash script? For example, depending on the text value of a variable I parse out of an xml file, I want to assign it a numerical values. Example: if ; then VAR="25" fi if ; then VAR="25" fi Can these two... (3 Replies)
Discussion started by: audiophile
3 Replies

3. 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

4. Shell Programming and Scripting

How do I execute multiple statements within If then else

Please help me. I have been doing this for several hours. Here is the code if then echo a b c d >> file.txt echo 1111 >> file.txt fi The reason I want the two echo is because I want these statements printed on multiple lines. I keep getting error . First it tells me... (2 Replies)
Discussion started by: asemota
2 Replies

5. Shell Programming and Scripting

Running multiple if statements

Hi, Hav automated a process, and it is working fine. for first process alone status = ` ps -ef |grep a ` if then echo " Success" > temp/logfile else echo " Failure" > temp/logfile fi Now I hav to write script to automated some 2 process and then send mail using cron.. ... (5 Replies)
Discussion started by: NehaKrish
5 Replies

6. Shell Programming and Scripting

execute multiple statements in if-else

how can we execute multiple statements in else condition i have if then statement else statements fi in else condition i have multiple statements but it executing only one statement is there any way to execute multiple statements (4 Replies)
Discussion started by: nani1984
4 Replies

7. Shell Programming and Scripting

Multiple if Statements

Hi All, I need to check for 3 conditions and if all the 3 are not satified need to say that services are not running.... is the below code correct. #********** Check to see if Service 1 is still running************** if then echo "$datetimestamp: Service1 is not running" >>... (4 Replies)
Discussion started by: ch33ry
4 Replies

8. Shell Programming and Scripting

Multiple while statements?

I'm working on a script for class as a final project. We have to ask for values (city, state, zip) five times, but the state can only be MI, IN, IL, or OH. I'm trying to do this with a while loop inside of a while loop, but I have no idea how to do it properly. Here's what I have so far: ... (3 Replies)
Discussion started by: nickzourdos
3 Replies

9. UNIX for Dummies Questions & Answers

Multiple if statements

exmaple: file1 and file2 has 1 bit if then exit else send out email fi if then exit else send out email fi it exits the 1st if. did not continue with my 2nd if. thanks in advanced. Please use CODE tags are suggested on every page when you post an item in... (7 Replies)
Discussion started by: lawsongeek
7 Replies

10. Shell Programming and Scripting

Using multiple 'for' statements

Hello, I am new to scripting and I am trying to write a simple script that creates users and adds their passwords from two files; one a user list file and another a password list file. For example, I have two files already. $ cat file1 andy stephane aby paul $ cat file2 123 234... (4 Replies)
Discussion started by: FemoTheDon
4 Replies
vc(1)								   User Commands							     vc(1)

NAME
vc - version control SYNOPSIS
vc [-a] [-t] [-c char] [-s] [keyword=value... keyword=value] DESCRIPTION
This command is obsolete and will be removed in the next release. The vc command copies lines from the standard input to the standard output under control of its arguments and of ``control statements'' encountered in the standard input. In the process of performing the copy operation, user-declared keywords may be replaced by their string value when they appear in plain text and/or control statements. The copying of lines from the standard input to the standard output is conditional, based on tests (in control statements) of keyword val- ues specified in control statements or as vc command arguments. A control statement is a single line beginning with a control character, except as modified by the -t keyletter (see below). The default control character is colon (:), except as modified by the -c keyletter (see below). Input lines beginning with a backslash () followed by a control character are not control lines and are copied to the standard output with the backslash removed. Lines beginning with a back- slash followed by a non-control character are copied in their entirety. A keyword is composed of 9 or less alphanumerics; the first must be alphabetic. A value is any ASCII string that can be created with ed; a numeric value is an unsigned string of digits. Keyword values may not contain blanks or tabs. Replacement of keywords by values is done whenever a keyword surrounded by control characters is encountered on a version control state- ment. The -a keyletter (see below) forces replacement of keywords in all lines of text. An uninterpreted control character may be included in a value by preceding it with . If a literal is desired, then it too must be preceded by . OPTIONS
The following options are supported: -a Forces replacement of keywords surrounded by control characters with their assigned value in all text lines and not just in vc statements. -t All characters from the beginning of a line up to and including the first tab character are ignored for the purpose of detecting a control statement. If a control statement is found, all characters up to and including the tab are discarded. -cchar Specifies a control character to be used in place of the ``:'' default. -s Silences warning messages (not error) that are normally printed on the diagnostic output. vc recognizes the following version control statements: :dcl keyword[, ..., keyword] Declare keywords. All keywords must be declared. :asg keyword=value Assign values to keywords. An asg statement overrides the assignment for the corresponding keyword on the vc command line and all pre- vious asg statements for that keyword. Keywords that are declared but are not assigned values have null values. :if condition ... :end Skip lines of the standard input. If the condition is true, all lines between the if statement and the matching end statement are copied to the standard output. If the condition is false, all intervening lines are discarded, including control statements. Note: Intervening if statements and matching end statements are recognized solely for the purpose of maintaining the proper if-end matching. The syntax of a condition is: <cond> ::= [ ``not'' ] <or> <or> ::= <and> | <and> ``|'' <or> <and> ::= <exp> | <exp> ``&'' <and> <exp> ::= ``('' <or> ``)'' | <value> <op> <value> <op> ::= ``='' | ``!='' | ``<'' | ``>'' <value> ::= <arbitrary ASCII string> | <numeric string> The available operators and their meanings are: = equal != not equal & and | or > greater than < less than () used for logical groupings not may only occur immediately after the if, and when present, inverts the value of the entire condition The > and < operate only on unsigned integer values (for example, : 012 > 12 is false). All other operators take strings as arguments (for example, : 012 != 12 is true). The precedence of the operators (from highest to lowest) is: = != > < all of equal precedence & | Parentheses may be used to alter the order of precedence. Values must be separated from operators or parentheses by at least one blank or tab. ::text Replace keywords on lines that are copied to the standard output. The two leading control characters are removed, and keywords sur- rounded by control characters in text are replaced by their value before the line is copied to the output file. This action is indepen- dent of the -a keyletter. :on :off Turn on or off keyword replacement on all lines. :ctl char Change the control character to char. :msg message Print message on the diagnostic output. :err message Print message followed by: ERROR: err statement on line ... (915) on the diagnostic output. vc halts execution, and returns an exit code of 1. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsprot | +-----------------------------+-----------------------------+ SEE ALSO
ed(1), attributes(5) SunOS 5.11 5 Jul 1990 vc(1)
All times are GMT -4. The time now is 11:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy