Sponsored Content
Top Forums Shell Programming and Scripting [solved] awk: return code from system() always 0 ?? Post 302831559 by zaxxon on Thursday 11th of July 2013 08:07:37 AM
Old 07-11-2013
Update:
It seems the cmd_str is a problem. It is a very long list of parameters and contains blanks, semicolons, double quotes. Somewhere there must be a problem, because when I issue the Perl script without parameters it returns a RC of 1 which is also displayed when I alter it in the script.
I have to check how I can encapsule that long string so that it will be handed over correctly and if the correct RC will be displayed.

Update:
I found out, that when there is a semicolon in string variable, that is handed over to system(), it will give the RC = 0, because the parameters delimeted by the semicolon are things like "msg=blabla" and this is a valid variable definiton in the shell, so it's RC = 0 Smilie
test.sh worked, because it had a shortened version of the command, where the semicolons were left out... sorry.

I tried escaping it, but that doesn't help - any ideas are welcome.
I can't change the delimeter to something else, because the server on the other side expects them as delimeter.

Last edited by zaxxon; 07-11-2013 at 09:47 AM..
 

10 More Discussions You Might Find Interesting

1. Programming

How to get system() function executed cmd return value ?

Hi, How I can get system function executed command return value ? I want to know mv command success or not ? #include <stdio.h> main() { int ret; ret = system( "mv x.dat y.dat" ); printf( "system ret:\n", ret ); } (3 Replies)
Discussion started by: haiudhaya
3 Replies

2. Programming

Return code from system()

Hi, Can any one help me in knowing how can I get the return codes/Error codes when using the system() command to fork a command? Regards, MK (1 Reply)
Discussion started by: mradulkaushik
1 Replies

3. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

4. Shell Programming and Scripting

C, sh, perl, system(): Can't transfer a return code appropriately: help, pls

I am using a perl-script from C-code, executing it by the 'system(..)' comand. The problem is to return the perl-return code to the C correctly. Default the 'system()' shell is Bourne: sh My try: (perl_src.c_pl - the perl script; t_sys - C-program with system() call (I will show it... (7 Replies)
Discussion started by: alex_5161
7 Replies

5. Shell Programming and Scripting

[Solved] File System Monitoring Script

Hello Scripts Guru I had created a shell script to monitor the threshold of the file system, but some where it is not giving the correct output. Request to all to hel me out I am getting the following output /dev/vg00/lvol3 mounted on 1865224 10% / is 2097152% /dev/vg00/lvol1 mounted on... (2 Replies)
Discussion started by: indrajit_renu
2 Replies

6. Shell Programming and Scripting

Managing awk return code over SSH command

Hello all, This bellow code works. I'm just trying to find a simplified way to achieve this. I'm sure there is an easier way and it must be to simple for me to find. Verify that the OS version is 6.1. If not exit the script. Of course if i just put a && exit 1 at the end of the ssh... (11 Replies)
Discussion started by: maverick72
11 Replies

7. HP-UX

[Solved] Mount HP-UX File System in Windows 7

Hello, We just got a rx4640 that is running on: HP-UX B.11.31 U ia64 2426088954 unlimited-user license There is a plenty of space in it and we would like to use it for storage. I can access with ftp and place the files in there but i need to mount the file system in every PC that is running... (7 Replies)
Discussion started by: gjk
7 Replies

8. HP-UX

[Solved] Increase the file system size

Dear Friends, I would like to increase the size of a file system from 10GB to 15GB. System is runing on HP-UX 11.31. Please help in the matter. Regards, Bhagawati Pandey (3 Replies)
Discussion started by: BPANDEY
3 Replies

9. Shell Programming and Scripting

[Solved] Process dies when launched in system startup script

Good morning! I'm trying to add Maven to the system boot by the moment without success. Testing the operation of the script I realize that the process isn't persistent when the program is launched with the start option. ---- #Startup Script ---- #! /bin/sh # chkconfig: 345 99 1 #... (5 Replies)
Discussion started by: carpannav
5 Replies

10. Red Hat

[Solved] Redhat system is not booting in GUI mode

Hi Guys Required help in Redhat 6.1. After installation of Redhat 6.1 in VMware system is not going in GUI mode. please to solve the issue... Thanks... (5 Replies)
Discussion started by: deviltech
5 Replies
GETOPT(1)							   User Commands							 GETOPT(1)

NAME
getopt - parse command options (enhanced) SYNOPSIS
getopt optstring parameters getopt [options] [--] optstring parameters getopt [options] -o|--options optstring [options] [--] parameters DESCRIPTION
getopt is used to break up (parse) options in command lines for easy parsing by shell procedures, and to check for legal options. It uses the GNU getopt(3) routines to do this. The parameters getopt is called with can be divided into two parts: options which modify the way getopt will parse (options and -o|--options optstring in the SYNOPSIS), and the parameters which are to be parsed (parameters in the SYNOPSIS). The second part will start at the first non-option parameter that is not an option argument, or after the first occurrence of '--'. If no '-o' or '--options' option is found in the first part, the first parameter of the second part is used as the short options string. If the environment variable GETOPT_COMPATIBLE is set, or if its first parameter is not an option (does not start with a '-', this is the first format in the SYNOPSIS), getopt will generate output that is compatible with that of other versions of getopt(1). It will still do parameter shuffling and recognize optional arguments (see section COMPATIBILITY for more information). Traditional implementations of getopt(1) are unable to cope with whitespace and other (shell-specific) special characters in arguments and non-option parameters. To solve this problem, this implementation can generate quoted output which must once again be interpreted by the shell (usually by using the eval command). This has the effect of preserving those characters, but you must call getopt in a way that is no longer compatible with other versions (the second or third format in the SYNOPSIS). To determine whether this enhanced version of getopt(1) is installed, a special test option (-T) can be used. OPTIONS
-a, --alternative Allow long options to start with a single '-'. -h, --help Output a small usage guide and exit successfully. No other output is generated. -l, --longoptions longopts The long (multi-character) options to be recognized. More than one option name may be specified at once, by separating the names with commas. This option may be given more than once, the longopts are cumulative. Each long option name in longopts may be fol- lowed by one colon to indicate it has a required argument, and by two colons to indicate it has an optional argument. -n, --name progname The name that will be used by the getopt(3) routines when it reports errors. Note that errors of getopt(1) are still reported as coming from getopt. -o, --options shortopts The short (one-character) options to be recognized. If this option is not found, the first parameter of getopt that does not start with a '-' (and is not an option argument) is used as the short options string. Each short option character in shortopts may be followed by one colon to indicate it has a required argument, and by two colons to indicate it has an optional argument. The first character of shortopts may be '+' or '-' to influence the way options are parsed and output is generated (see section SCANNING MODES for details). -q, --quiet Disable error reporting by getopt(3). -Q, --quiet-output Do not generate normal output. Errors are still reported by getopt(3), unless you also use -q. -s, --shell shell Set quoting conventions to those of shell. If no -s argument is found, the BASH conventions are used. Valid arguments are cur- rently 'sh' 'bash', 'csh', and 'tcsh'. -u, --unquoted Do not quote the output. Note that whitespace and special (shell-dependent) characters can cause havoc in this mode (like they do with other getopt(1) implementations). -T, --test Test if your getopt(1) is this enhanced version or an old version. This generates no output, and sets the error status to 4. Other implementations of getopt(1), and this version if the environment variable GETOPT_COMPATIBLE is set, will return '--' and error sta- tus 0. -V, --version Output version information and exit successfully. No other output is generated. PARSING
This section specifies the format of the second part of the parameters of getopt (the parameters in the SYNOPSIS). The next section (OUT- PUT) describes the output that is generated. These parameters were typically the parameters a shell function was called with. Care must be taken that each parameter the shell function was called with corresponds to exactly one parameter in the parameter list of getopt (see the EXAMPLES). All parsing is done by the GNU getopt(3) routines. The parameters are parsed from left to right. Each parameter is classified as a short option, a long option, an argument to an option, or a non-option parameter. A simple short option is a '-' followed by a short option character. If the option has a required argument, it may be written directly after the option character or as the next parameter (ie. separated by whitespace on the command line). If the option has an optional argument, it must be written directly after the option character if present. It is possible to specify several short options after one '-', as long as all (except possibly the last) do not have required or optional arguments. A long option normally begins with '--' followed by the long option name. If the option has a required argument, it may be written directly after the long option name, separated by '=', or as the next argument (i.e. separated by whitespace on the command line). If the option has an optional argument, it must be written directly after the long option name, separated by '=', if present (if you add the '=' but nothing behind it, it is interpreted as if no argument was present; this is a slight bug, see the BUGS). Long options may be abbrevi- ated, as long as the abbreviation is not ambiguous. Each parameter not starting with a '-', and not a required argument of a previous option, is a non-option parameter. Each parameter after a '--' parameter is always interpreted as a non-option parameter. If the environment variable POSIXLY_CORRECT is set, or if the short option string started with a '+', all remaining parameters are interpreted as non-option parameters as soon as the first non-option parame- ter is found. OUTPUT
Output is generated for each element described in the previous section. Output is done in the same order as the elements are specified in the input, except for non-option parameters. Output can be done in compatible (unquoted) mode, or in such way that whitespace and other special characters within arguments and non-option parameters are preserved (see QUOTING). When the output is processed in the shell script, it will seem to be composed of distinct elements that can be processed one by one (by using the shift command in most shell lan- guages). This is imperfect in unquoted mode, as elements can be split at unexpected places if they contain whitespace or special charac- ters. If there are problems parsing the parameters, for example because a required argument is not found or an option is not recognized, an error will be reported on stderr, there will be no output for the offending element, and a non-zero error status is returned. For a short option, a single '-' and the option character are generated as one parameter. If the option has an argument, the next parame- ter will be the argument. If the option takes an optional argument, but none was found, the next parameter will be generated but be empty in quoting mode, but no second parameter will be generated in unquoted (compatible) mode. Note that many other getopt(1) implementations do not support optional arguments. If several short options were specified after a single '-', each will be present in the output as a separate parameter. For a long option, '--' and the full option name are generated as one parameter. This is done regardless whether the option was abbrevi- ated or specified with a single '-' in the input. Arguments are handled as with short options. Normally, no non-option parameters output is generated until all options and their arguments have been generated. Then '--' is generated as a single parameter, and after it the non-option parameters in the order they were found, each as a separate parameter. Only if the first character of the short options string was a '-', non-option parameter output is generated at the place they are found in the input (this is not supported if the first format of the SYNOPSIS is used; in that case all preceding occurrences of '-' and '+' are ignored). QUOTING
In compatible mode, whitespace or 'special' characters in arguments or non-option parameters are not handled correctly. As the output is fed to the shell script, the script does not know how it is supposed to break the output into separate parameters. To circumvent this problem, this implementation offers quoting. The idea is that output is generated with quotes around each parameter. When this output is once again fed to the shell (usually by a shell eval command), it is split correctly into separate parameters. Quoting is not enabled if the environment variable GETOPT_COMPATIBLE is set, if the first form of the SYNOPSIS is used, or if the option '-u' is found. Different shells use different quoting conventions. You can use the '-s' option to select the shell you are using. The following shells are currently supported: 'sh', 'bash', 'csh' and 'tcsh'. Actually, only two 'flavors' are distinguished: sh-like quoting conventions and csh-like quoting conventions. Chances are that if you use another shell script language, one of these flavors can still be used. SCANNING MODES
The first character of the short options string may be a '-' or a '+' to indicate a special scanning mode. If the first calling form in the SYNOPSIS is used they are ignored; the environment variable POSIXLY_CORRECT is still examined, though. If the first character is '+', or if the environment variable POSIXLY_CORRECT is set, parsing stops as soon as the first non-option parame- ter (ie. a parameter that does not start with a '-') is found that is not an option argument. The remaining parameters are all inter- preted as non-option parameters. If the first character is a '-', non-option parameters are outputted at the place where they are found; in normal operation, they are all collected at the end of output after a '--' parameter has been generated. Note that this '--' parameter is still generated, but it will always be the last parameter in this mode. COMPATIBILITY
This version of getopt(1) is written to be as compatible as possible to other versions. Usually you can just replace them with this ver- sion without any modifications, and with some advantages. If the first character of the first parameter of getopt is not a '-', getopt goes into compatibility mode. It will interpret its first parameter as the string of short options, and all other arguments will be parsed. It will still do parameter shuffling (ie. all non-option parameters are outputted at the end), unless the environment variable POSIXLY_CORRECT is set. The environment variable GETOPT_COMPATIBLE forces getopt into compatibility mode. Setting both this environment variable and POSIXLY_COR- RECT offers 100% compatibility for 'difficult' programs. Usually, though, neither is needed. In compatibility mode, leading '-' and '+' characters in the short options string are ignored. RETURN CODES
getopt returns error code 0 for successful parsing, 1 if getopt(3) returns errors, 2 if it does not understand its own parameters, 3 if an internal error occurs like out-of-memory, and 4 if it is called with -T. EXAMPLES
Example scripts for (ba)sh and (t)csh are provided with the getopt(1) distribution, and are optionally installed in /usr/share/getopt/ or /usr/share/docs/ in util-linux subdirectory. ENVIRONMENT
POSIXLY_CORRECT This environment variable is examined by the getopt(3) routines. If it is set, parsing stops as soon as a parameter is found that is not an option or an option argument. All remaining parameters are also interpreted as non-option parameters, regardless whether they start with a '-'. GETOPT_COMPATIBLE Forces getopt to use the first calling format as specified in the SYNOPSIS. BUGS
getopt(3) can parse long options with optional arguments that are given an empty optional argument (but can not do this for short options). This getopt(1) treats optional arguments that are empty as if they were not present. The syntax if you do not want any short option variables at all is not very intuitive (you have to set them explicitly to the empty string). AUTHOR
Frodo Looijaard <frodo@frodo.looijaard.name> SEE ALSO
getopt(3), bash(1), tcsh(1). AVAILABILITY
The getopt command is part of the util-linux package and is available from Linux Kernel Archive <ftp://ftp.kernel.org/pub/linux/utils/util- linux/>. util-linux June 2012 GETOPT(1)
All times are GMT -4. The time now is 01:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy