10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi All,
We have few scripts where we are using grep -w option to do exact matching of the pattern. This works fine on most of our servers.
But I have encounter a very old HP-UX System(HP-UX B.11.00) where grep -w option is not available.
This is causing my scripts to fail. I need to change... (7 Replies)
Discussion started by: veeresh_15
7 Replies
2. Shell Programming and Scripting
I am trying to code for the addition of a new argument to the command line, the option D to a code that already has ABC (below). When I use make to compile it, it displays: invalid option --D. I did define the global d variable, as well as initialized it inside the main function of the C code. I... (9 Replies)
Discussion started by: Alabama
9 Replies
3. Shell Programming and Scripting
What is the significance of the *) and ?) in the below code.
while getopts a:b:c:he opt
do
case $opt in
a) _name="$OPTARG";;
b) _project="$OPTARG";;
c) line="$OPTARG";;
e) _cmd="XX";;
h) Projects=1;;
*) echo "$OPTARG is an invalid option";
my_exit 1;;
?)... (3 Replies)
Discussion started by: posix
3 Replies
4. Shell Programming and Scripting
To find all the files in your home directory that have been edited in some way since the last tar file, use this command:
find . -newer backup.tar.gz
Is anyone familiar with an older solution?
looking to identify files older then 15mins across several directories.
thanks,
manny (2 Replies)
Discussion started by: mr_manny
2 Replies
5. UNIX for Dummies Questions & Answers
Hi
I need to use getopt option and I have no idea what it is or how to use it.
I need to use it on this awk script:
awk -F, -v cellid="$1" -v paramval="$2" -v oldfile="$3" -v newfile="$4" '$2==cellid{$3=newvalue}1' OFS="," $3 > $4
I tried reading up on it but I just confuse... (2 Replies)
Discussion started by: ladyAnne
2 Replies
6. Shell Programming and Scripting
Hello,
I am processing a text file which contains only words with few combination of characters (it is a dictionary file).
example:
havana
have
haven
haven't
havilland
havoc
Is there a way to exclude only 1 to 8 character long words which not include space or special characters : '-`~.. so... (5 Replies)
Discussion started by: alekkz
5 Replies
7. Shell Programming and Scripting
:)
Can anybody help me about how to use getopt in shell scripting. (3 Replies)
Discussion started by: darshakraut
3 Replies
8. 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
9. Shell Programming and Scripting
Hi all,
I am parsing command line options using getopts.
The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument.
Below is the script:
while getopts :hd:t:s:l:p:f: opt
do
case "$opt" in
-h|-\?)... (2 Replies)
Discussion started by: gurukottur
2 Replies
10. Shell Programming and Scripting
#!/bin/sh
set -- `getopt "abco:" "$@"`
a= b= c= o=
while :
do
case "$1" in
-a) a=1;;
-b) b=1;;
-c) c=1;;
-o) shift; o="$1";;
--) break;;
esac
shift
done
shift # get rid of --
# rest of script...
# e.g.
ls -l $@ (6 Replies)
Discussion started by: Hitori
6 Replies
GETOPT(1) BSD General Commands Manual GETOPT(1)
NAME
getopt -- parse command options
SYNOPSIS
args=`getopt optstring $*`
set -- `getopt optstring $*`
DESCRIPTION
getopt is used to break up options in command lines for easy parsing by shell procedures, and to check for legal options. [Optstring] is a
string of recognized option letters (see getopt(3)); if a letter is followed by a colon, the option is expected to have an argument which may
or may not be separated from it by white space. The special option ``--'' is used to delimit the end of the options. getopt will place
``--'' in the arguments at the end of the options, or recognize it if used explicitly. The shell arguments ($1, $2, ...) are reset so that
each option is preceded by a ``-'' and in its own shell argument; each option argument is also in its own shell argument.
getopt should not be used in new scripts; use the shell builtin getopts instead.
EXAMPLES
The following code fragment shows how one might process the arguments for a command that can take the options [a] and [b], and the option
[c], which requires an argument.
args=`getopt abc: $*`
if [ $? -ne 0 ]; then
echo 'Usage: ...'
exit 2
fi
set -- $args
while [ $# -gt 0 ]; do
case "$1" in
-a|-b)
flag=$1
;;
-c)
carg=$2; shift
;;
--)
shift; break
;;
esac
shift
done
This code will accept any of the following as equivalent:
cmd -acarg file file
cmd -a -c arg file file
cmd -carg -a file file
cmd -a -carg -- file file
IEEE Std 1003.2 (``POSIX.2'') mandates that the sh(1) set command return the value of 0 for the exit status. Therefore, the exit status of
the getopt command is lost when getopt and the sh(1) set command are used on the same line. The example given is one way to detect errors
found by getopt.
DIAGNOSTICS
getopt prints an error message on the standard error output when it encounters an option letter not included in [optstring].
SEE ALSO
sh(1), getopt(3)
HISTORY
Written by Henry Spencer, working from a Bell Labs manual page. Behavior believed identical to the Bell version.
BUGS
Whatever getopt(3) has.
Arguments containing white space or embedded shell metacharacters generally will not survive intact; this looks easy to fix but isn't.
The error message for an invalid option is identified as coming from getopt rather than from the shell procedure containing the invocation of
getopt; this again is hard to fix.
The precise best way to use the set command to set the arguments without disrupting the value(s) of shell options varies from one shell ver-
sion to another.
BSD
November 28, 2009 BSD