Sponsored Content
Top Forums Shell Programming and Scripting if statement - how can I do 2 arguments? Post 302184800 by Darklight on Sunday 13th of April 2008 05:05:59 AM
Old 04-13-2008
if statement - how can I do 2 arguments?

I am new to shell, and I am trying to do a if statement like the following:

if [ -z $1 -a -z $2]; then

basically it works fine if both arguments of the if are met, however the next elif is:

elif [ -z $1 ]; then

if the conditions of the elif are met, then it says "final1.sh: line 67: [: too many arguments"

Line 67 is the first if statement.

Basically I am trying to write an "if" that says "if no arguments are there do this.. else if only one of the arguments (specified) is there, do this."

Hope this makes sense Smilie

Micko
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

2. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

3. Shell Programming and Scripting

Too many arguments?

I can't find anything wrong with this line of code, it works when there is one file in the directory but more than one i get a "too many arguements2 error if ; then am i missing something? (3 Replies)
Discussion started by: Alendrin
3 Replies

4. Shell Programming and Scripting

grep with two arguments to arguments to surch for

Hello, is it possible to give grep two documents to surche for? like grep "test" /home/one.txt AND /home/two.txt ? thanks (1 Reply)
Discussion started by: Cybertron
1 Replies

5. Shell Programming and Scripting

case statement for different cmd arguments

Hello friends, I have a boubt passing different arguments at a time for any one option in below code. I would also like to check which option has been selected (any one of i, r, u ) so that whether or not matching argument passed can be verified. for i and r - install and re-install -... (4 Replies)
Discussion started by: pd2
4 Replies

6. Shell Programming and Scripting

creating printf statement using user arguments

I am writing a script in bash and want to perform the operation I check number of arguments and make a print statement with the passes arguments If I pass 3 arguments I will do printf "$frmt" "$1" "$2" "$3"If I have 4 arguments I do printf "$frmt" "$1" "$2" "$3" "$4"etc (4 Replies)
Discussion started by: kristinu
4 Replies

7. Programming

Passing arguments from command line to switch case statement in C

Hi Am pretty new to C.. Am trying to pass the arguments from command line and use them in switch case statement.. i have tried the following #include <stdlib.h> main(int argc, char* argv) { int num=0; if ( argc == 2 ) num = argv; printf("%d is the num value",num); switch ( num ) ... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies

8. Shell Programming and Scripting

Arguments in usage statement

Hello, I have a question regarding the usage statement of a script. I have 2 parameters "--pto" and "--pto_list". To start the script I will need one of them. Both together are not possible. How this would be printed out within a usage statement? My suggestion would be: Usage:... (4 Replies)
Discussion started by: API
4 Replies

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

10. UNIX for Beginners Questions & Answers

If statement arguments

I'm stuck on a particular problem and need some guidance. I have a file with a name and a phone number in it (teledir.txt). I need to do a $# in a separate script to take a positional parameter and check to see if it is in the file. To quote the question: If one argument is supplied, check... (6 Replies)
Discussion started by: Eric7giants
6 Replies
UNIFDEF(1)							Programmer's Manual							UNIFDEF(1)

NAME
unifdef, unifdefall -- remove preprocessor conditionals from code SYNOPSIS
unifdef [-bBcdehKkmnsStV] [-Ipath] [-[i]Dsym[=val]] [-[i]Usym] ... [-x {012}] [-M backext] [-o outfile] [infile ...] unifdefall [-Ipath] ... file DESCRIPTION
The unifdef utility selectively processes conditional cpp(1) directives. It removes from a file both the directives and any additional text that they specify should be removed, while otherwise leaving the file alone. The unifdef utility acts on #if, #ifdef, #ifndef, #elif, #else, and #endif lines. A directive is only processed if the symbols specified on the command line are sufficient to allow unifdef to get a definite value for its control expression. If the result is false, the directive and the following lines under its control are removed. If the result is true, only the directive is removed. An #ifdef or #ifndef directive is passed through unchanged if its controlling symbol is not specified on the command line. Any #if or #elif control expression that has an unknown value or that unifdef cannot parse is passed through unchanged. By default, unifdef ignores #if and #elif lines with constant expressions; it can be told to process them by specifying the -k flag on the command line. It understands a commonly-used subset of the expression syntax for #if and #elif lines: integer constants, integer values of symbols defined on the command line, the defined() operator, the operators !, <, >, <=, >=, ==, !=, &&, ||, and parenthesized expressions. A kind of ``short circuit'' evaluation is used for the && operator: if either operand is definitely false then the result is false, even if the value of the other operand is unknown. Similarly, if either operand of || is definitely true then the result is true. In most cases, the unifdef utility does not distinguish between object-like macros (without arguments) and function-like arguments (with arguments). If a macro is not explicitly defined, or is defined with the -D flag on the command-line, its arguments are ignored. If a macro is explicitly undefined on the command line with the -U flag, it may not have any arguments since this leads to a syntax error. The unifdef utility understands just enough about C to know when one of the directives is inactive because it is inside a comment, or affected by a backslash-continued line. It spots unusually-formatted preprocessor directives and knows when the layout is too odd for it to handle. A script called unifdefall can be used to remove all conditional cpp(1) directives from a file. It uses unifdef -s and cpp -dM to get lists of all the controlling symbols and their definitions (or lack thereof), then invokes unifdef with appropriate arguments to process the file. OPTIONS
-Dsym=val Specify that a symbol is defined to a given value which is used when evaluating #if and #elif control expressions. -Dsym Specify that a symbol is defined to the value 1. -Usym Specify that a symbol is undefined. If the same symbol appears in more than one argument, the last occurrence dominates. -iDsym[=val] -iUsym C strings, comments, and line continuations are ignored within #ifdef and #ifndef blocks controlled by symbols specified with these options. -b Replace removed lines with blank lines instead of deleting them. Mutually exclusive with the -B option. -B Compress blank lines around a deleted section. Mutually exclusive with the -b option. -c Complement, i.e., lines that would have been removed or blanked are retained and vice versa. -d Turn on printing of debugging messages. -e By default, unifdef will report an error if it needs to remove a preprocessor directive that spans more than one line, for example, if it has a multi-line comment hanging off its right hand end. The -e flag makes it ignore the line instead. -h Print help. -Ipath Specifies to unifdefall an additional place to look for #include files. This option is ignored by unifdef for compatibility with cpp(1) and to simplify the implementation of unifdefall. -K Always treat the result of && and || operators as unknown if either operand is unknown, instead of short-circuiting when unknown op- erands can't affect the result. This option is for compatibility with older versions of unifdef. -k Process #if and #elif lines with constant expressions. By default, sections controlled by such lines are passed through unchanged because they typically start ``#if 0'' and are used as a kind of comment to sketch out future or past development. It would be rude to strip them out, just as it would be for normal comments. -m Modify one or more input files in place. -M backext Modify input files in place, and keep backups of the original files by appending the backext to the input filenames. -n Add #line directives to the output following any deleted lines, so that errors produced when compiling the output file correspond to line numbers in the input file. -o outfile Write output to the file outfile instead of the standard output when processing a single file. -s Instead of processing an input file as usual, this option causes unifdef to produce a list of symbols that appear in expressions that unifdef understands. It is useful in conjunction with the -dM option of cpp(1) for creating unifdef command lines. -S Like the -s option, but the nesting depth of each symbol is also printed. This is useful for working out the number of possible com- binations of interdependent defined/undefined symbols. -t Disables parsing for C strings, comments, and line continuations, which is useful for plain text. This is a blanket version of the -iD and -iU flags. -V Print version details. -x {012} Set exit status mode to zero, one, or two. See the EXIT STATUS section below for details. The unifdef utility takes its input from stdin if there are no file arguments. You must use the -m or -M options if there are multiple input files. You can specify inut from stdin or output to stdout with '-'. The unifdef utility works nicely with the -Dsym option of diff(1). EXIT STATUS
In normal usage the unifdef utility's exit status depends on the mode set using the -x option. If the exit mode is zero (the default) then unifdef exits with status 0 if the output is an exact copy of the input, or with status 1 if the output differs. If the exit mode is one, unifdef exits with status 1 if the output is unmodified or 0 if it differs. If the exit mode is two, unifdef exits with status zero in both cases. In all exit modes, unifdef exits with status 2 if there is an error. The exit status is 0 if the -h or -V command line options are given. DIAGNOSTICS
Too many levels of nesting. Inappropriate #elif, #else or #endif. Obfuscated preprocessor control line. Premature EOF (with the line number of the most recent unterminated #if). EOF in comment. SEE ALSO
cpp(1), diff(1) HISTORY
The unifdef command appeared in 2.9BSD. ANSI C support was added in FreeBSD 4.7. AUTHORS
The original implementation was written by Dave Yost <Dave@Yost.com>. Tony Finch <dot@dotat.at> rewrote it to support ANSI C. BUGS
Expression evaluation is very limited. Handling one line at a time means preprocessor directives split across more than one physical line (because of comments or backslash-newline) cannot be handled in every situation. Trigraphs are not recognized. There is no support for symbols with different definitions at different points in the source file. The text-mode and ignore functionality does not correspond to modern cpp(1) behaviour. February 21, 2012
All times are GMT -4. The time now is 06:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy