Sponsored Content
Top Forums Shell Programming and Scripting Getopts in the subshell of ksh Post 302851091 by hitmansilentass on Friday 6th of September 2013 06:03:03 PM
Old 09-06-2013
Quote:
Originally Posted by Scott
You can only save one of v's arguments into "vname". Is that what you mean?

Unless you process it within the loop, you'll need to store more values, for which you can use an array:
Code:
$ cat myScript
while getopts f:v:s opt; do
 case "$opt" in
  f) echo f has $OPTARG;;
  v) v_args[${#v_args[@]}]=$OPTARG;;
  s) echo s has nothing;;
esac
done

echo ${v_args[0]}
echo ${v_args[1]}

$ ./myScript -v abc -v 123
abc
123

Notice also that "s" has no arguments (f:v:s).
Thanks Scot for all your help Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Subshell Question

The profile of the user is empty. Then before I run the script I want I run a parameter file that populates the variables for oracle. ORACLE_HOME ORACLE_BASE ORACLE_SID PATH etc ... But it seems that these variables are not making it to the shell I am in because when I do an echo on... (6 Replies)
Discussion started by: lesstjm
6 Replies

2. Shell Programming and Scripting

ksh: can you use getopts in a function?

I wrote a script that uses getopts and it works fine. However, I would like to put the function in that script in a startup file (.kshrc or .profile). I took the "main" portion of the script and made it a function in the startup script. I source the startup script but it doesn't seem to parse... (4 Replies)
Discussion started by: lyonsd
4 Replies

3. Shell Programming and Scripting

ksh and getopts

Hello, I'm writing a script that uses command line options and arguments. To handle these, I'm using getopts. Is there a way to set up an option where an argument is optional? What I'm trying to do is offer -v for verbose output, -vv for increased output -vvv etc. Any suggestions? ... (1 Reply)
Discussion started by: garskoci
1 Replies

4. Shell Programming and Scripting

ksh function getopts get leading underscore unless preceded by hyphen

If I call my function with grouped options: "logm -TDIWEFO 'message' ", then only the "T" gets parsed correctly. The subsequent values returned have underscores prefixed to the value: "_D", "_I", etc. If I "logm -T -DIWEFO 'message' ", the "T" and the "D" are OK, but "I" through "O" get the... (2 Replies)
Discussion started by: kchriste
2 Replies

5. Shell Programming and Scripting

getopts in a subshell

Hello, I've a little problem with one of my ksh scripts and I manage to narrow it to the script here: #!/bin/ksh writeLog() { paramHandle="unknown" OPTIND=1 while getopts :i: option $* do case $option in i) paramHandle=${OPTARG} ;; esac done echo... (2 Replies)
Discussion started by: Dahu
2 Replies

6. Shell Programming and Scripting

Basename in subshell

Hi All, I would like to improve my bash scripting skill and found a problem which I do not understand. Task is to search and print files in directory (and subdirecories) which contains its own name. Files can have spaces in name. This one works fine for files in main directory, but not for... (4 Replies)
Discussion started by: new_item
4 Replies

7. Shell Programming and Scripting

Help on getopts in ksh

I am trying to make a Shell Script in KSH on Linux box and Solaris box which takes few arguments... with long options using getopts (not getopt). I have my sample code... at the end I will say my requirement... Please help me folks... $ cat dummy #!/bin/bash # Argument = -t test -r server... (6 Replies)
Discussion started by: explorer007
6 Replies

8. Shell Programming and Scripting

ksh "getopts" -- Unsetting an Option

I use the "getopts" ksh built-in to handle command-line options, and I'm looking for a clean/standard way to "unset" an option on the command line. I don't know if this is a technical question about getopts or more of a style/standards question. Anyway, I understand that getopts processes its... (4 Replies)
Discussion started by: Matt Miller
4 Replies

9. Shell Programming and Scripting

Using getopts in ksh

I want to use getopts in ksh scripting to obtain multiple values currently im using while getopts vt: opt do case "$opt" in -v) vn=$OPTARG;; -t) tn="$OPTARG";; ;; # terminate while loop esac done however variables vn tn dont store any... (3 Replies)
Discussion started by: E.sh
3 Replies

10. Shell Programming and Scripting

ksh - default value for getopts option's argument

Hello everyone, I need help in understanding the default value for getopts option's argument in ksh. I've written a short test script: #!/bin/ksh usage(){ printf "Usage: -v and -m are mandatory\n\n" } while getopts ":v#m:" opt; do case $opt in v) version="$OPTARG";; ... (1 Reply)
Discussion started by: da1
1 Replies
MSGFMT_GET_PATTERN(3)							 1						     MSGFMT_GET_PATTERN(3)

MessageFormatter::getPattern - Get the pattern used by the formatter

	Object oriented style

SYNOPSIS
public string MessageFormatter::getPattern (void ) DESCRIPTION
Procedural style string msgfmt_get_pattern (MessageFormatter $fmt) Get the pattern used by the formatter PARAMETERS
o $fmt - The message formatter RETURN VALUES
The pattern string for this message formatter EXAMPLES
Example #1 msgfmt_get_pattern(3) example <?php $fmt = msgfmt_create( "en_US", "{0, number} monkeys on {1, number} trees" ); echo "Default pattern: '" . msgfmt_get_pattern( $fmt ) . "' "; echo "Formatting result: " . msgfmt_format( $fmt, array(123, 456) ) . " "; msgfmt_set_pattern( $fmt, "{0, number} trees hosting {1, number} monkeys" ); echo "New pattern: '" . msgfmt_get_pattern( $fmt ) . "' "; echo "Formatted number: " . msgfmt_format( $fmt, array(123, 456) ) . " "; ?> Example #2 OO example <?php $fmt = new MessageFormatter( "en_US", "{0, number} monkeys on {1, number} trees" ); echo "Default pattern: '" . $fmt->getPattern() . "' "; echo "Formatting result: " . $fmt->format(array(123, 456)) . " "; $fmt->setPattern("{0, number} trees hosting {1, number} monkeys" ); echo "New pattern: '" . $fmt->getPattern() . "' "; echo "Formatted number: " . $fmt->format(array(123, 456)) . " "; ?> The above example will output: Default pattern: '{0,number} monkeys on {1,number} trees' Formatting result: 123 monkeys on 456 trees New pattern: '{0,number} trees hosting {1,number} monkeys' Formatted number: 123 trees hosting 456 monkeys SEE ALSO
msgfmt_create(3), msgfmt_set_pattern(3). PHP Documentation Group MSGFMT_GET_PATTERN(3)
All times are GMT -4. The time now is 08:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy