07-23-2012
Hi,
My script requires 3 command line arguments to execute it.
If someone does pass these 3 arguments then it should return that invalid invocation and the usage.But in my script even if i do not pass any argument it is not going in that if part. Also when i am not passing any argument then also set is returning the value as 0 .i.e. successfull execution instead of 1 .i.e failure. Since it is returning 0 it is not going into that if part where i have mentioned if [$? -ne 0];then echo "something".
Please suggest.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I have a script that facillitates NDM (Connect::\Direct) transfer to remote hosts. This script uses getopts to parse through the parameters passed to it and to set appropriate variables based upon what was passed in.
Kickoff="mv $PATH/$FILE1 $PATH/$FILE2"
ndm_shell.ksh -p $Node -s $Source -d... (3 Replies)
Discussion started by: google
3 Replies
2. Shell Programming and Scripting
I need to parse parameters but the arguments could be NULL,example:
> cat getopts.sh
while getopts "a:b:" opt 2>/dev/null
do
case "${opt}" in
a) echo "A:${OPTARG}" ;;
b) echo "B:${OPTARG}" ;;
*) exit 1 ;;
esac
done
> getopts.sh -a TEST1 -b TEST2... (5 Replies)
Discussion started by: Klashxx
5 Replies
3. Shell Programming and Scripting
Hi
i have part of the scripts below ,getopt for -h or ? not working for me.
can anybody tell me if this sytax right or wrong.
#!/usr/bin/ksh
program=$(basename $0)
#####################################################################################
function usageerr
{
RC=1
... (3 Replies)
Discussion started by: GrepMe
3 Replies
4. Shell Programming and Scripting
while getopts l:f:s:o:h: c
do
case $c in
l) tail -${OPTARG} /etc/passwd
exit 2;;
f) head -${OPTARG} /etc/passwd
exit 3;;
s) grep ${OPTARG} /etc/passwd | cut -d: -f7
exit 4;;
o) OARG=$OPTARG
exit 5;;
h) ... (3 Replies)
Discussion started by: nadman123
3 Replies
5. Shell Programming and Scripting
Hi, I am a new member to unix.com.
Actually I am facing a problem with getopts. In my script i have used getopts to parse the parameters. when i use the script as shown below its working fine:
find_status -p all ### where find_status is a script name.
But even if I pass more than one... (3 Replies)
Discussion started by: pvamsikr
3 Replies
6. UNIX for Advanced & Expert Users
i was going through the man page of getopts
this particular section is not clear to me can anyone please
clarify in a little detail so that i can understand the concept
MANPAGE::
Since getopts affects the current shell execution environ-
ment, it is generally provided as a... (7 Replies)
Discussion started by: mobydick
7 Replies
7. Shell Programming and Scripting
How do I get the getopts command to display whats written at my help option if no option is types in? For example,
myscript.sh -h
will bring up my help option, however, I also want
myscript.sh
to do the same!
#!/bin/bash
while getopts :abh opt
do case "$opt" in... (2 Replies)
Discussion started by: linuxkid
2 Replies
8. Shell Programming and Scripting
Hi everyone
I want to know how can we pass multiple argument in getopts
suppose
PARAMS="abcd"
while getopts ${PARMS} FLAG
do
case ${FLAG} in
(a)
(b)
(c)
(d)
esac (6 Replies)
Discussion started by: aishsimplesweet
6 Replies
9. Shell Programming and Scripting
In the below code
while getopts :rfw:d:s:a: options
do
case "$options" in
r) echo reverse;;
f) echo forward;;
w) window=$OPTARG;;
d) duration=$OPTARG;;
s) search=$OPTARG;;
a) value=$OPTARG;;
*) help; exit;;
esac
done
... (2 Replies)
Discussion started by: Amutha
2 Replies
10. Shell Programming and Scripting
can anyone spot a problem with the below:
$
$ cat getopts.sh
#!/bin/sh
usage() { echo "myscript.sh local /tmp data.txt 600s -query" 1>&2; exit 1; }
while... (4 Replies)
Discussion started by: SkySmart
4 Replies
LEARN ABOUT MOJAVE
tcl_evalex
Tcl_Eval(3) Tcl Library Procedures Tcl_Eval(3)
__________________________________________________________________________________________________________________________________________________
NAME
Tcl_EvalObjEx, Tcl_EvalFile, Tcl_EvalObjv, Tcl_Eval, Tcl_EvalEx, Tcl_GlobalEval, Tcl_GlobalEvalObj, Tcl_VarEval, Tcl_VarEvalVA - execute
Tcl scripts
SYNOPSIS
#include <tcl.h>
int
Tcl_EvalObjEx(interp, objPtr, flags)
int
Tcl_EvalFile(interp, fileName)
int
Tcl_EvalObjv(interp, objc, objv, flags)
int
Tcl_Eval(interp, script)
int
Tcl_EvalEx(interp, script, numBytes, flags)
int
Tcl_GlobalEval(interp, script)
int
Tcl_GlobalEvalObj(interp, objPtr)
int
Tcl_VarEval(interp, part, part, ... (char *) NULL)
int
Tcl_VarEvalVA(interp, argList)
ARGUMENTS
Tcl_Interp *interp (in) Interpreter in which to execute the script. The interpreter's result is modified to hold the result or
error message from the script.
Tcl_Obj *objPtr (in) A Tcl object containing the script to execute.
int flags (in) ORed combination of flag bits that specify additional options. TCL_EVAL_GLOBAL and TCL_EVAL_DIRECT are
currently supported.
const char *fileName (in) Name of a file containing a Tcl script.
int objc (in) The number of objects in the array pointed to by objPtr; this is also the number of words in the com-
mand.
Tcl_Obj **objv (in) Points to an array of pointers to objects; each object holds the value of a single word in the command
to execute.
int numBytes (in) The number of bytes in script, not including any null terminating character. If -1, then all characters
up to the first null byte are used.
const char *script (in) Points to first byte of script to execute (null-terminated and UTF-8).
char *part (in) String forming part of a Tcl script.
va_list argList (in) An argument list which must have been initialized using va_start, and cleared using va_end.
_________________________________________________________________
DESCRIPTION
The procedures described here are invoked to execute Tcl scripts in various forms. Tcl_EvalObjEx is the core procedure and is used by many
of the others. It executes the commands in the script stored in objPtr until either an error occurs or the end of the script is reached.
If this is the first time objPtr has been executed, its commands are compiled into bytecode instructions which are then executed. The
bytecodes are saved in objPtr so that the compilation step can be skipped if the object is evaluated again in the future.
The return value from Tcl_EvalObjEx (and all the other procedures described here) is a Tcl completion code with one of the values TCL_OK,
TCL_ERROR, TCL_RETURN, TCL_BREAK, or TCL_CONTINUE, or possibly some other integer value originating in an extension. In addition, a result
value or error message is left in interp's result; it can be retrieved using Tcl_GetObjResult.
Tcl_EvalFile reads the file given by fileName and evaluates its contents as a Tcl script. It returns the same information as Tcl_EvalOb-
jEx. If the file could not be read then a Tcl error is returned to describe why the file could not be read. The eofchar for files is
"32" (^Z) for all platforms. If you require a "^Z" in code for string comparison, you can use "