output should be
This is needed because we already have a system which uses only parameters. Now the last parameter is optional. So It's hard to add extra optional parameter.
Also changing the current parameter to all option is not recommended because the client does not want to change all the existing cron entries fearing high risk in production.
The standards specify that options should come before operands; not after. There are ways to work around that, but I don't see any real reason to bend the guidelines for what you're trying to do. There are a couple of easy ways to deal with this. I've included sample code below for both of these.
The 1st way uses getopts the way it was intended and would be described in UNIX-like man pages with the SYNOPIS:
When using this form, the script requires two operands (parm1 and parm2) and accepts an option which can either be specified as a single command-line argument (-sopt_val) as as two command-line arguments (-s opt_val). In either case, if opt_val contains multiple words, the whitespace between words can be escape or quoted. If parm1 happens to start with a minus sign (-), getopts will accept an operand of -- to indicate end-of-options.
A sample bash (this will also work with any other POSIX conforming shell such as ksh) script for this method is:
Sample commands and corresponding output for this form follow:
produces:
produces:
produces:
produces:
The 2nd way does not use getopts, but instead just uses $# to determine how many command-line arguments are present. Again it always requires two operands, but this one accepts (but does not require) one more operand and would be described in UNIX-like man pages with the synopsis:
A sample bash script (that, again, will work with any POSIX conforming shell) for this method is:
Sample commands and corresponding output for this form follow:
produces:
produces:
produces:
Both of these scripts set the default value for the optional value to "None". It is clear visually for these examples. Depending on how you want to use this optional value, an empty string (or any other string you want) may be more appropriate.
Note that both of these sample scripts redirect all diagnostic messages to stderr (rather than stdout). And, if and only if a diagnostic message is written, the exit status will be non-zero.
Note also that even if a script does not (currently) accept options, it is still a good idea to include comehting like:
So a user can always issue the command:
to get a synopsis for the utility including a list of the currently accepted options, and can use:
to protect itself in csae the 1st operand might start with a minus sign that should not be interpreted as the start of an option string.
Hope this helps...
This User Gave Thanks to Don Cragun For This Post:
Hello,
I am new to shell (i.e. linux bash) programming and have the following question:
When using this wget command I can download a certain website that needs login information by passing a previously acquired cookie:
wget --header='Cookie: SID=ac658ef0876b24ff456' somewebsite.comAs... (5 Replies)
Hi ,
I am passing date parameter through file
my shell script testing.sh is
#set -x
#set -v
asd=$1
asd1=$2
echo $asd
echo $asd1
Passing parameter as below
sh testing.sh `cat file1.txt`
Output (2 Replies)
Hi,
I've written a script where eleven parameter to be passed from command line
which is inserting into an oracle table,
it is working but the tenth and 11th parameter are not accepting as given
it is referring to 1st parameter.
HERE IS THE SCRIPT
#!/bin/ksh
#set -o
echo $*... (4 Replies)
i am passing input parameter 'one_two' to the script , the script output should display the result as below
one_1two
one_2two
one_3two
if
then
echo " Usage : <$0> <DATABASE> "
exit 0
else
for DB in 1 2 3
do
DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}`
done
fi (5 Replies)
Hi Folks
I have got to the point where I can specify the arguments but how to pass an option is still mystery to me. Example:
temp.csh a b c d
set temp1 = $argv
set temp2 = $argv
set temp3 = $argv
echo $temp1
a
echo $temp2
b
echo $temp3
c d
I WANT:
temp.csh a b c d -S 1
set temp1... (2 Replies)
Hi,
PW='/as sysdba'; export PW
in other module I call sqlplus ${PW} (this line I unable to change!)
How I can define PW so that sqlplus calls PW in quotes i.e sqlplus '/as sysdba'
I tried like this
PW="'/as sysdba'"; export PW - no luck
Thanks in advance (2 Replies)
Hello World~:)
$ rbash
$ cd ..
rbash: cd: restricted
$ ls -l /bin/rbash
lrwxrwxrwx 1 root root 4 2008-11-02 15:56 /bin/rbash -> bash
rbash is a symbolic link to bash
but why does rbash execute 'bash -r' instead of 'bash'
i want to know how symbolic link executes command with option or... (4 Replies)
Hi all
I have a script which will take input as filename and passes it to a java program. It is as follows
--------------------------------
FILENAME=$1
echo $FILENAME
${JAVA_HOME}/bin/java -cp DateProvider $FILENAME
-------------------------------------------------
when I execute the same... (2 Replies)
Hi,
How to pass parameter to makefile?
Please let me know if any one knows and also please put an example of makefile with this feature.
thanks,
Manju. (3 Replies)