Sponsored Content
Top Forums Shell Programming and Scripting How to execute default in getopts when no option is given ? Post 302443274 by pravsripad on Sunday 8th of August 2010 01:34:05 AM
Old 08-08-2010
How to execute default in getopts when no option is given ?

hi, here is a ksh script i wrote using getopts...

i want to find out how i can run it in default mode when no option is mentioned and no arguments are provided... ?

i.e if the script name is final1, then just running final1 should run in default mode....


Code:
while getopts 1:2:3:4: mode 
do
case $mode in
 1) echo "You have chosen mode1"
        echo "user specified month and year"
        echo $OPTARG
        exit;
         
        echo "Default, Current Month"
        
        ;;
 2) echo " You have chosen mode2"
        if -f $OPTARG 
        then
        echo "File Specified Manually"

        else
        echo "Log error if files are missing"
        fi
        ;;

 3) echo "you have chosen mode 3"
    echo "number of working Days"
        case $OPTARG in
        x)echo "Runs for all days of month";;
        ?) echo "Runs for working days only";;
        esac
        ;;
 4) echo "You have chosen mode 4"
    echo "Client Selection mode"
    
        exit;;
 ?) echo "Invalid mode is selected";;
esac
done


Last edited by Scott; 08-08-2010 at 06:03 AM.. Reason: Code tags, please...
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

option followed by : taking next option if argument missing with getopts

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

2. Shell Programming and Scripting

getopts with non-option arguments?

Hello everyone, Is it possible to use getopts and also receive arguments without option flags? e.g. myscript arg1 arg2 -a arg3 -b arg4 If so, how do you stop getopts from exiting as soon as it detects the non-option arguments? (2 Replies)
Discussion started by: kdelok
2 Replies

3. Shell Programming and Scripting

getopts: bad option(s)

Hi, I have a script that ran perfectly on Solaris 5.8 However after upgrade to Solaris 5.10 it started failing. I invoke the script as below: ./TestScript3.ksh --dir $APP_DATA_IN_OLD $NDM_DATA/$NEXT_FILE When i execute it i get the following error "getopts: dir bad option(s)". Please let... (1 Reply)
Discussion started by: JoeJoseph
1 Replies

4. Shell Programming and Scripting

getopts with repeat of same option

Hello, Does getopts have some way of handling the use of an option that requires a parameter more than once on the command line. e.g. mycmd -a john -a jane I came up with a solution using arrays (shown below), but wonder if getopts has some other way of handling it. Other solutions... (2 Replies)
Discussion started by: CarlosNC
2 Replies

5. UNIX for Dummies Questions & Answers

how does symbolic link execute command with option or parameter

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)
Discussion started by: lifegeek
4 Replies

6. Shell Programming and Scripting

getopts fails to error on option w/o dash

I have a script with several options and during testing I found that the \? option does not handle options without dashes as I would expect. Then I run the script with any option that does not include a dash, it runs the script when I would expect \? to catch it and error. I've tried this with... (2 Replies)
Discussion started by: HexKnot
2 Replies

7. Shell Programming and Scripting

Using default value with getopts and case

Hey Guys I have a program in shell which is reading default values from a file filename: default MAN=Value1 MANPD=997 REPPD=P1G6 Now the code calling is #!/bin/sh . /home/default while getopts t:D: name do (4 Replies)
Discussion started by: its
4 Replies

8. Shell Programming and Scripting

ksh "getopts" -- Unsetting an Option

I use the "getopts" ksh built-in to handle command-line options, and I'm looking for a clean/standard way to "unset" an option on the command line. I don't know if this is a technical question about getopts or more of a style/standards question. Anyway, I understand that getopts processes its... (4 Replies)
Discussion started by: Matt Miller
4 Replies

9. Shell Programming and Scripting

Getopts option -please help

Hello, I am using below code in AIX env to interpret -n option given in argument while executing the script .I want to give another argument -t #!/bin/sh #set -x while getopts ":n:" opt; do case "$opt" in n) host=$OPTARG shift 2 ;; *)... (3 Replies)
Discussion started by: Vishal_dba
3 Replies

10. Shell Programming and Scripting

ksh - default value for getopts option's argument

Hello everyone, I need help in understanding the default value for getopts option's argument in ksh. I've written a short test script: #!/bin/ksh usage(){ printf "Usage: -v and -m are mandatory\n\n" } while getopts ":v#m:" opt; do case $opt in v) version="$OPTARG";; ... (1 Reply)
Discussion started by: da1
1 Replies
echo(3XCURSES)						  X/Open Curses Library Functions					    echo(3XCURSES)

NAME
echo, noecho - enable/disable terminal echo SYNOPSIS
cc [ flag... ] file... -I /usr/xpg4/include -L /usr/xpg4/lib -R /usr/xpg4/lib -lcurses [ library... ] c89 [ flag... ] file... -lcurses [ library... ] #include <curses.h> int echo(void); int noecho(void); DESCRIPTION
The echo() function enables Echo mode for the current screen. The noecho() function disables Echo mode for the current screen. Initially, curses software echo mode is enabled and hardware echo mode of the tty driver is disabled. The echo() and noecho() functions control soft- ware echo only. Hardware echo must remain disabled for the duration of the application, else the behavior is undefined. RETURN VALUES
Upon successful completion, these functions return OK. Otherwise, they return ERR. ERRORS
No errors are defined. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
getch(3XCURSES), getstr(3XCURSES), initscr(3XCURSES), libcurses(3XCURSES), scanw(3XCURSES), attributes(5), standards(5) SunOS 5.10 5 Jun 2002 echo(3XCURSES)
All times are GMT -4. The time now is 08:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy