02-09-2005
it works! thanks. it seem that in the loop's last iteration, i = -- and so the error message prints every time because I did not have a case for that. After adding the case the problem went away.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
scriptname
i have made a script to perform so tasks and i managed to complete the tasks for all the options
the problem i am facing is that i can run the scripts individually but i would like to make it such that it can accept multiple options and give me the appropriate output
e.g.... (1 Reply)
Discussion started by: problems
1 Replies
2. Shell Programming and Scripting
I m trying to use getopt
This is my script, but it doesn't take argument in variable,
Please help.
set - - `getopt mscl: $*`
if
then
echo "Exiting...."
exit 2
fi
for i in $*
do
case $i in
-m) MAIL="$i"; shift;;
-s) SCRIPT=$OPTARG; shift;;
-c) COB=$OPTARG; shift;;... (2 Replies)
Discussion started by: darshakraut
2 Replies
3. Shell Programming and Scripting
Hi,
I want to use the getopt function to parse some arguments for a script.
while getopts "i:f:r:" OPTION
do
case $OPTION in
i) iter=$OPTARG;;
f) frame=$OPTARG;;
r) roi=$OPTARG;;
?) echo Usage: ......
exit 2;;
esac
done
However, I... (5 Replies)
Discussion started by: giorgos193
5 Replies
4. Programming
Hello ,
How to resolve below compilation error.activity_type is a member of structure and the output from databse will be stored in structure.Expected output wil l be either D or N or C .
sample struct format:
struct a{
char acAtivity_type;
}
code:
switch (a->activity_type)... (1 Reply)
Discussion started by: jagan_kalluri
1 Replies
5. Shell Programming and Scripting
I am just learning Tcl and there are few things about it that is perplexing me. I have a question about the switch statement.
Why are these two switch statements giving me different results?
$ cat test_switch.tcl
#!/usr/bin/tcl
set foo "abc"
switch abc a - b {puts "No. 1"} $foo {puts... (2 Replies)
Discussion started by: SFNYC
2 Replies
6. Shell Programming and Scripting
hi,
how to access console of a switch having rj45 on switch side to db 9 female on pc side console cable which needs to be connected to one console server having rj11 on its side and db 9 female on other end.i.e. on switch side,console cable has rj45 and db 9 pin female connector on other side of... (1 Reply)
Discussion started by: pankajd
1 Replies
7. Shell Programming and Scripting
I started writing a script to save the files from a camera I got the other day, which mounts in /Volumes , and I got into it and started building this menu. The only problem is that the switch case is coming up as a syntax error at the parenthesis after a case. Here is the code:
while :
do
... (2 Replies)
Discussion started by: snakemasterAK
2 Replies
8. Programming
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
9. Shell Programming and Scripting
Hi All,
An old work friend wrote a script which I've been trying to understand how a section of it currently works and work out how i can add some command line switches which i can use later in the script to append the output depending on the command line arguements.
Currently it works by... (1 Reply)
Discussion started by: mutley2202
1 Replies
10. Programming
Having trouble with the logic when looping over this switch case again:
for (j = 0; data != 0; j++){
switch(data){
case 'c':
output = ranit(r_brace_array);
break;
case 'h':
output = ranit(pipe_array);
break;
... (6 Replies)
Discussion started by: Azrael
6 Replies
GETOPT(3) 1 GETOPT(3)
getopt - Gets options from the command line argument list
SYNOPSIS
array getopt (string $options, [array $longopts])
DESCRIPTION
Parses options passed to the script.
PARAMETERS
o $options
- Each character in this string will be used as option characters and matched against options passed to the script starting with a
single hyphen ( -). For example, an option string "x" recognizes an option -x. Only a-z, A-Z and 0-9 are allowed.
o $longopts
- An array of options. Each element in this array will be used as option strings and matched against options passed to the script
starting with two hyphens ( --). For example, an longopts element "opt" recognizes an option --opt.
The $options parameter may contain the following elements:
oIndividual characters (do not accept values)
oCharacters followed by a colon (parameter requires value)
oCharacters followed by two colons (optional value)
Option values are the first argument after the string. If a value is required, it does not matter whether the value has leading white
space or not. See note.
Note
Optional values do not accept " " (space) as a separator.
Note
The format for the $options and $longopts is almost the same, the only difference is that $longopts takes an array of options
(where each element is the option) whereas $options takes a string (where each character is the option).
RETURN VALUES
This function will return an array of option / argument pairs or FALSE on failure.
Note
The parsing of options will end at the first non-option found, anything that follows is discarded.
CHANGELOG
+--------+---------------------------------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+---------------------------------------------------+
| 5.3.0 | |
| | |
| | Added support for "=" as argument/value separa- |
| | tor. |
| | |
| 5.3.0 | |
| | |
| | Added support for optional values (specified |
| | with "::"). |
| | |
| 5.3.0 | |
| | |
| | Parameter $longopts is available on all systems. |
| | |
| 5.3.0 | |
| | |
| | This function is no longer system dependent, and |
| | now works on Windows, too. |
| | |
+--------+---------------------------------------------------+
EXAMPLES
Example #1
getopt(3) example: The basics
<?php
// Script example.php
$options = getopt("f:hp:");
var_dump($options);
?>
shell> php example.php -fvalue -h
The above example will output:
array(2) {
["f"]=>
string(5) "value"
["h"]=>
bool(false)
}
Example #2
getopt(3) example: Introducing long options
<?php
// Script example.php
$shortopts = "";
$shortopts .= "f:"; // Required value
$shortopts .= "v::"; // Optional value
$shortopts .= "abc"; // These options do not accept values
$longopts = array(
"required:", // Required value
"optional::", // Optional value
"option", // No value
"opt", // No value
);
$options = getopt($shortopts, $longopts);
var_dump($options);
?>
shell> php example.php -f "value for f" -v -a --required value --optional="optional value" --option
The above example will output:
array(6) {
["f"]=>
string(11) "value for f"
["v"]=>
bool(false)
["a"]=>
bool(false)
["required"]=>
string(5) "value"
["optional"]=>
string(14) "optional value"
["option"]=>
bool(false)
}
Example #3
getopt(3) example: Passing multiple options as one
<?php
// Script example.php
$options = getopt("abc");
var_dump($options);
?>
shell> php example.php -aaac
The above example will output:
array(2) {
["a"]=>
array(3) {
[0]=>
bool(false)
[1]=>
bool(false)
[2]=>
bool(false)
}
["c"]=>
bool(false)
}
SEE ALSO
$argv.
PHP Documentation Group GETOPT(3)