Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Check for Empty Command Argument Post 302136751 by liketheshell on Wednesday 19th of September 2007 01:24:22 PM
Old 09-19-2007
You can try doing
if [ "$#" - ne 2 ] then

do something else.

fi

So if the first argument is passed to the script then there is no problem. If the second argument is not supplied then do something else. Hope that helps a bit.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to check if the argument contain wildcard (*,?) ?

In a script , i would like to check if the argument ( $1, $2 inside the script) contain wildcard (*,? etc). how do i do it? > script_name arg1 arg* $1 (arg1) does not contain wildcard, but $2 (arg* )contains wildcard. how can i tell in script? i need to do this is because : if arg1... (3 Replies)
Discussion started by: gusla
3 Replies

2. Shell Programming and Scripting

How can I make the for command check to see if a file is empty before executing?

Here is the command in question for f in $(<uploads); do . I only want this to execute if uploads is not empty. If uploads is empty I want the script to quit, actually before the for command. If its not apparent uploads is a text file. Chris (3 Replies)
Discussion started by: chrchcol
3 Replies

3. Shell Programming and Scripting

Check for empty string

Hello All, I have written shell script whcih at the max 3 parameters. When only one commandline argument and other two command line arguments are passed as empty string like eg : archive ' ' ' ' Then i need to check whether the commandline... (12 Replies)
Discussion started by: rahman_riyaz
12 Replies

4. Shell Programming and Scripting

check if file is empty

How do I check if a file is empty in a sh script I want to test in my shell script if the output file is empty and if it is do one thing and if it isnt empty do another? any ideas? (8 Replies)
Discussion started by: stolz
8 Replies

5. Shell Programming and Scripting

check whether the directory is empty or not

I have the list of users in user.log, under each user folder there is sub1 folder is there. i want to check whether sub1 is empty or not, if it is empty i have to skip that user user folder and iterate next user folders. i have the sample code,its not giving not proper results. while read line... (8 Replies)
Discussion started by: KiranKumarKarre
8 Replies

6. Shell Programming and Scripting

check empty directory !!!

I need to check if a directory is empty using an if condition in the pseudocode below if ; then else although i looked at a few forums on this topic, I left feeling a little unclear and i could not use the command successfully what can i substitute in the if conditon above,... (2 Replies)
Discussion started by: allah_waris45
2 Replies

7. Shell Programming and Scripting

Cannot compare argument in if statement in csh/grep command if argument starts with “-“

If ($argv == “-debug”) then Echo “in loop” Endif But this is not working. If I modify this code and remove “-“, then it works. Similarly I am getting problem using grep command also Grep “-debug” Filename Can someone please help me on how to resolve these... (1 Reply)
Discussion started by: sarbjit
1 Replies

8. Shell Programming and Scripting

How to check whether a variable is empty or contains some value?

hi, i want to check whether a a variable contains some value or is empty in a shell script. so if the variable contains some value i want to do some job and if the variable doesnt contain any value then i need to skip that job. here is a sample script read_filenames.sh contains ... (5 Replies)
Discussion started by: Little
5 Replies

9. Shell Programming and Scripting

Argument check

All, I'm writing an argument checking block and running into an error. I want to confirm that $1 is one of two values. Here is what I have: if ]; then echo -e "\nPlease check your first augument. You used \"$1\" which is not recognized. Please see usage:" usage ... (9 Replies)
Discussion started by: hburnswell
9 Replies

10. Shell Programming and Scripting

Cant check empty string

Hello So i have that script collection, in which i have a single script to create a configuration file. In there, i have multiple occourences of something like this: prj_title=$(tui-read "What is the TITLE? ($prj_name):") ] && prj_title="${prj_name/_/ }" They all work as expected, if... (5 Replies)
Discussion started by: sea
5 Replies
INET6_OPT_INIT(3)					   BSD Library Functions Manual 					 INET6_OPT_INIT(3)

NAME
inet6_opt_init, inet6_opt_append, inet6_opt_finish, inet6_opt_set_val, inet6_opt_next, inet6_opt_find, inet6_opt_get_val -- IPv6 Hop-by-Hop and Destination Options manipulation SYNOPSIS
#include <netinet/in.h> int inet6_opt_init(void *extbuf, socklen_t extlen); int inet6_opt_append(void *extbuf, socklen_t extlen, int offset, u_int8_t type, socklen_t len, u_int8_t align, void **databufp); int inet6_opt_finish(void *extbuf, socklen_t extlen, int offset); int inet6_opt_set_val(void *databuf, int offset, void *val, socklen_t vallen); int inet6_opt_next(void *extbuf, socklen_t extlen, int offset, u_int8_t *typep, socklen_t *lenp, void **databufp); int inet6_opt_find(void *extbuf, socklen_t extlen, int offset, u_int8_t type, socklen_t *lenp, void **databufp); int inet6_opt_get_val(void *databuf, socklen_t offset, void *val, socklen_t vallen); DESCRIPTION
Building and parsing the Hop-by-Hop and Destination options is complicated. The advanced sockets API defines a set of functions to help applications create and manipulate Hop-by-Hope and Destination options. These functions use the formatting rules specified in Appendix B in RFC2460, i.e., that the largest field is placed last in the option. The function prototypes for these functions are all contained in the <netinet/in.h> header file. inet6_opt_init The inet6_opt_init() function returns the number of bytes needed for an empty extension header, one without any options. If the extbuf argu- ment points to a valid section of memory then the inet6_opt_init() function also initializes the extension header's length field. When attempting to initialize an extension buffer passed in the extbuf argument extlen must be a positive multiple of 8 or else the function fails and returns -1 to the caller. inet6_opt_append The inet6_opt_append() function can perform to different jobs. When a valid extbuf argument is supplied it appends an option to the exten- sion buffer and returns the updated total length as well as a pointer to the newly created option in databufp. If the value of extbuf is NULL then the inet6_opt_append(function, only, reports, what, the, total, length, would) be if the option were actually appended. The len and align arguments specify the length of the option and the required data alignment which must be used when appending the option. The offset argument should be the length returned by the inet6_opt_init() function or a previous call to inet6_opt_append(). The type argument is the 8-bit option type. After inet6_opt_append() has been called, the application can use the buffer pointed to by databufp directly, or use inet6_opt_set_val() to specify the data to be contained in the option. Option types of 0 and 1 are reserved for the Pad1 and PadN options. All other values from 2 through 255 may be used by applications. The length of the option data is contained in an 8-bit value and so may contain any value from 0 through 255. The align parameter must have a value of 1, 2, 4, or 8 and cannot exceed the value of len. The alignment values represent no alignment, 16 bit, 32 bit and 64 bit alignments respectively. inet6_opt_finish The inet6_opt_finish() calculates the final padding necessary to make the extension header a multiple of 8 bytes, as required by the IPv6 extension header specification, and returns the extension header's updated total length. The offset argument should be the length returned by inet6_opt_init() or inet6_opt_append(). When extbuf is not NULL the function also sets up the appropriate padding bytes by inserting a Pad1 or PadN option of the proper length. If the extension header is too small to contain the proper padding then an error of -1 is returned to the caller. inet6_opt_set_val The inet6_opt_set_val() function inserts data items of various sizes into the data portion of the option. The databuf argument is a pointer to memory that was returned by the inet6_opt_append() call and the offset argument specifies where the option should be placed in the data buffer. The val argument points to an area of memory containing the data to be inserted into the extension header, and the vallen argument indicates how much data to copy. The caller should ensure that each field is aligned on its natural boundaries as described in Appendix B of RFC2460. The function returns the offset for the next field which is calculated as offset + vallen and is used when composing options with multiple fields. inet6_opt_next The inet6_opt_next() function parses received extension headers. The extbuf and extlen arguments specify the location and length of the extension header being parsed. The offset argument should either be zero, for the first option, or the length value returned by a previous call to inet6_opt_next() or inet6_opt_find(). The return value specifies the position where to continue scanning the extension buffer. The option is returned in the arguments typep, lenp, and databufp. typep, lenp, and databufp point to the 8-bit option type, the 8-bit option length and the option data respectively. This function does not return any PAD1 or PADN options. When an error occurs or there are no more options the return value is -1. inet6_opt_find The inet6_opt_find() function searches the extension buffer for a particular option type, passed in through the type argument. If the option is found then the lenp and databufp arguments are updated to point to the option's length and data respectively. extbuf and extlen must point to a valid extension buffer and give its length. The offset argument can be used to search from a location anywhere in the extension header. inet6_opt_get_val The inet6_opt_get_val() function extracts data items of various sizes in the data portion of the option. The databuf is a pointer returned by the inet6_opt_next() or inet6_opt_find() functions. The val argument points where the data will be extracted. The offset argument speci- fies from where in the data portion of the option the value should be extracted; the first byte of option data is specified by an offset of zero. It is expected that each field is aligned on its natural boundaries as described in Appendix B of RFC2460. The function returns the offset for the next field by calculating offset + vallen which can be used when extracting option content with mul- tiple fields. Robust receivers must verify alignment before calling this function. DIAGNOSTICS
All the functions return -1 on an error. EXAMPLES
RFC3542 gives comprehensive examples in Section 23. KAME also provides examples in the advapitest directory of its kit. SEE ALSO
W. Stevens, M. Thomas, E. Nordmark, and T. Jinmei, Advanced Sockets API for IPv6, RFC3542, October 2002. S. Deering and R. Hinden, Internet Protocol, Version 6 (IPv6) Specification, RFC2460, December 1998. HISTORY
The implementation first appeared in KAME advanced networking kit. STANDARDS
The functions are documented in ``Advanced Sockets API for IPv6'' (RFC3542). BSD
December 23, 2004 BSD
All times are GMT -4. The time now is 10:49 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy