Sponsored Content
Top Forums Shell Programming and Scripting How to pass parameters transparently into a sub script Post 302291170 by rikxik on Tuesday 24th of February 2009 11:59:46 PM
Old 02-25-2009
You problem is that the argument parsing is not happening properly. The getopt / getopts command can be used to accept arguments in typical unix style and they will parse arguments corretly & flexibly.

Example
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to pass two or more parameters to the main in shell script

Hey Guys from the below script what I understood is we are sending the the first parameter as input to the main (){} file main > $LOGFILE 2>&1 but can we send two or three parameter as input to this main file as main > $LOGFILE 2>&1 2>&2 like this Can any one plz help I need to writ a... (0 Replies)
Discussion started by: pinky
0 Replies

2. Shell Programming and Scripting

How to pass parameters to an awk file?

I have an awk file where I need to pass a filename and a value as a parameter from a sh script. I need to know how to pass those values in the sh script and how to use the same in the awk file. Thanks in advance!!! Geetha (3 Replies)
Discussion started by: iamgeethuj
3 Replies

3. Shell Programming and Scripting

Pass parameters to function

Hi, for example I have this function: function get_param () { test=echo "some string" test2=echo "someother string" } I want to call this function and get test or test2 result, how do I do that ? Thank you (2 Replies)
Discussion started by: ktm
2 Replies

4. Shell Programming and Scripting

want to pass parameters to awk script from shell script

Hello, I have this awk script that I want to execute by passing parameters through a shell script. I'm a little confused. This awk script removes duplicates from an input file. Ok, so I have a .sh file called rem_dups.sh #!/usr/bin/sh... (4 Replies)
Discussion started by: script_op2a
4 Replies

5. Shell Programming and Scripting

need to pass parameters to working and tested awk script

I have a working and tested AWK script that removes duplicates from an input file and generates an output file without the duplicates. I had help from my other post to develop it: ... (3 Replies)
Discussion started by: script_op2a
3 Replies

6. Shell Programming and Scripting

call another shell script and pass parameters to that shell script

Hi, I basically have 2 shell scripts. One is a shell script will get the variable value from the user. The variable is nothing but the IP of the remote system. Another shell script is a script that does the job of connecting to the remote system using ssh. This uses a expect utility in turn. ... (2 Replies)
Discussion started by: sunrexstar
2 Replies

7. Emergency UNIX and Linux Support

Pass two parameters

Hi I have a batch file aaa.exe which needs two input parameters: Usually the command's format likes aaa 555 10000 But I want to use parameters to do it. aaa $1 $2 These two parameters come from a text file list.txt 41800497 41801375 41814783 41816135 41814930 41816135 41819987 41820843... (4 Replies)
Discussion started by: zhshqzyc
4 Replies

8. Shell Programming and Scripting

Need to pass parameters to an "at" script...

but the man page seems to not have that feature. Am I missing something? This works: $ foo.sh bar abcThis doesn't: $ at now -f foo.sh bar abcTIA, Ron (2 Replies)
Discussion started by: RonJohn
2 Replies

9. Shell Programming and Scripting

Bash- Command run from script does not pass full parameters with spaces inside

There's a JavaScript file that I call from command line (there's a framework) like so: ./RunDiag.js param1:'string one here' param2:'string two here' I have a shell script where I invoke the above command. I can run it in a script as simple as this #!/bin/bash stuff="./RunDiag.js... (4 Replies)
Discussion started by: AcerAspirant
4 Replies

10. Shell Programming and Scripting

Pass Parameters to awk command

I need to pass values at runtime for the below awk command where l is the length and partial.txt is the file name. awk -v l=285 '{s="%-"l"s\n";printf(s,$0);}' partial.txt > temp1.txt; (5 Replies)
Discussion started by: Amrutha24
5 Replies
getopt(1)							   User Commands							 getopt(1)

NAME
getopt - parse command options SYNOPSIS
set -- ` getopt optstring $ * ` DESCRIPTION
The getopts command supersedes getopt. For more information, see NOTES below. getopt is used to break up options in command lines for easy parsing by shell procedures and to check for legal options. optstring is a string of recognized option letters; see getopt(3C). If a letter is followed by a colon (:), the option is expected to have an argument which may or may not be separated from it by white space. The special option - is used to delimit the end of the options. If it is used explicitly, getopt recognizes it; otherwise, getopt generates it; in either case, getopt places it at the end of the options. The posi- tional parameters ($1 $2 ...) of the shell are reset so that each option is preceded by a - and is in its own positional parameter; each option argument is also parsed into its own positional parameter. EXAMPLES
Example 1: Processing the arguments for a command The following code fragment shows how one might process the arguments for a command that can take the options -a or -b, as well as the option -o, which requires an argument: set -- `getopt abo: $*` if [ $? != 0 ] then echo $USAGE exit 2 fi for i in $* do case $i in -a | -b) FLAG=$i; shift;; -o) OARG=$2; shift 2;; --) shift; break;; esac done This code accepts any of the following as equivalent: cmd -aoarg filename1 filename2 cmd -a -o arg filename1 filename2 cmd -oarg -a filename1 filename2 cmd -a -oarg -- filename1 filename2 ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ SEE ALSO
intro(1), getopts(1), getoptcvt(1), sh(1), shell_builtins(1), getopt(3C), attributes(5) DIAGNOSTICS
getopt prints an error message on the standard error when it encounters an option letter not included in optstring. NOTES
getopt will not be supported in the next major release. For this release a conversion tool has been provided, namely, getoptcvt. For more information, see getopts(1) and getoptcvt(1). Reset optind to 1 when rescanning the options. getopt does not support the part of Rule 8 of the command syntax standard (see intro(1)) that permits groups of option-arguments following an option to be separated by white space and quoted. For example, cmd -a -b -o "xxx z yy" filename is not handled correctly. To correct this deficiency, use the getopts command in place of getopt. If an option that takes an option-argument is followed by a value that is the same as one of the options listed in optstring (referring to the earlier EXAMPLES section, but using the following command line: cmd -o -a filename getopt always treats it as an option-argument to -o; it never recognizes -a as an option. For this case, the for loop in the example shifts past the filename argument. SunOS 5.10 7 Jan 2000 getopt(1)
All times are GMT -4. The time now is 04:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy