Sponsored Content
Top Forums Shell Programming and Scripting Why getopts doesn't detect correctly my switches? Post 302297403 by pludi on Friday 13th of March 2009 09:38:05 AM
Old 03-13-2009
You used CURRENT_SWITCH in your output, which was still set to the last valid option. If there's an invalid option it's name will be set in OPTARG.
Code:
#!/bin/ksh

CURRENT_SWITCH=""
while getopts :a:b:c: SWITCHES
do
    case $SWITCHES in
        a)    CURRENT_SWITCH="a"
            print -n "The switch $CURRENT_SWITCH was selected with "
            print "the argument $OPTARG"
            ;;
            
        b)    CURRENT_SWITCH="b"
            print -n "The switch $CURRENT_SWITCH was selected with "
            print "the argument $OPTARG"
            ;;
            
        c)    CURRENT_SWITCH="c"
            print -n "The switch $CURRENT_SWITCH was selected with "
            print "the argument $OPTARG"
            ;;
            
        :)    print -n "CURRENT_SWITCH = $OPTARG : error : "
            print "missing argument"
            exit 1
            ;;
            
        \?)    print "unknown switch" 
            exit 1
            ;;
    esac
done

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Tar switches!!!

Hi, If i want to write my data on several tapes, (more than one tape), what switch(s) i need to use with tar. In other word if my data needs the sapce more than one tape & i don't wanna to compress or ... my data. so is it possible to write up to the end of the tape & it asks to put another... (1 Reply)
Discussion started by: nikk
1 Replies

2. SuSE

vsft doesn't work correctly

I install vsftpd server on 2 SUSE 10.2 servers. The first works perfectly, but the second doesn't work how I expect. The second works only over local network and doesn't over internet. The vsftpd.conf and ../xinetd.d/vsftpd are the same in 2 servers. The only different was when I threw to log in... (1 Reply)
Discussion started by: zhivko.neychev
1 Replies

3. Shell Programming and Scripting

Collect information from switches

Hi All , In my environment we have 12 SAN switches .Culd u pls help me for below queries . would like to telnet to all switches and collect information in daily basis with "switchstatus" command and store the output under /tmp/ folder on systemA . To keep passwords of 12switches in a... (1 Reply)
Discussion started by: chinni-script
1 Replies

4. Shell Programming and Scripting

echo switches

Hello All, I am writing an shell script but abruptly its not able to recognize switches in echo statement. #!/bin/bash top -n 1 -b>ankit host=`hostname` time=`cat ankit|grep load|tr -s " "|cut -d " " -f3` load=`cat ankit|grep load|tr -s " "|cut -d "," -f4|cut -d ":" -f2` ... (3 Replies)
Discussion started by: ajaincv
3 Replies

5. AIX

AIX doesn't detect smc1 media changer in ts3200 tape library

Hi all, I'm having a problem here my environment as follows. AIX 5.3 TL 10 running on a P6 p520 sever with 3 fibre channel cards and Tivoli Storage Manager TSM 5.4 and TS3200 Tape Library with 2 drives and 2 media changers. My problem as follows smc1 doesn't show up , I ran cfgmgr multiple... (6 Replies)
Discussion started by: h@foorsa.biz
6 Replies

6. AIX

AIX doesn't detect TS3200 tape library

Hi all, I have a problem here root@host1 / # lsdev -Cc tape rmt0 Defined 07-00-02 IBM 3580 Ultrium Tape Drive (FCP) rmt1 Defined 07-00-02 IBM 3580 Ultrium Tape Drive (FCP) smc0 Defined 07-00-02 IBM 3573 Tape Medium Changer (FCP) root@host1 / # cfgmgr -l fcs2 Method error... (2 Replies)
Discussion started by: h@foorsa.biz
2 Replies

7. Shell Programming and Scripting

[KornShell]: Why getopts doesn't detect disabled switches in this script?

Hi, My environement OS: Linux Fedora Core 17 X86_64 KSH version: sh (AT&T Research) 93u+ 2012-08-01 As I understand inside a Kornshell script, the getopts statement allows to collect information about the switches provided for the script (if any). Besides, it is possible to... (3 Replies)
Discussion started by: dariyoosh
3 Replies

8. Ubuntu

Ubuntu 16.04 doesn't detect my second monitor

I have Ubuntu 16.04 (dual boot with Windows 10) and a HP Spectre x360 laptop. I have recently bought a Dell Ultrasharp U2515H monitor, which I connect via a Dell docking station. When I plug the docking station to my laptop on Windows, both monitors are detected and everything works fine. ... (23 Replies)
Discussion started by: twelth_hour
23 Replies

9. UNIX for Beginners Questions & Answers

Getopts not echoing correctly

Hi, When I run the the following code: #!/bin/bash if ]; then usage fi if ] then echo "Do not execute this as root, use -s instead" fi SERVERFILE="servers" function usage { echo "USAGE: ${0} COMMAND" (4 Replies)
Discussion started by: mohca2020
4 Replies

10. Hardware

Dell XPS M1330 doesn't detect optical drive

I have a Dell XPS M1330 laptop. The OS is Windows 10. I had to replace the motherboard because it was bad. After replacing the motherboard I noticed the optical (DVD/CD) drive is neither detected in BIOS and OS nor making any noise at all. Everything else seems to be working fine. The optical drive... (3 Replies)
Discussion started by: milhan
3 Replies
print(1)							   User Commands							  print(1)

NAME
print - shell built-in function to output characters to the screen or window SYNOPSIS
ksh print [ -Rnprsu [n]] [arg...] DESCRIPTION
ksh The shell output mechanism. With no flags or with flag - or -, the arguments are printed on standard output as described by echo(1). OPTIONS
The following options are supported: -n suppresses new-line from being added to the output. -R -r (raw mode) ignore the escape conventions of echo. The -R option will print all subsequent arguments and options other than -n. -p causes the arguments to be written onto the pipe of the process spawned with |& instead of standard output. -s causes the arguments to be written onto the history file instead of standard output. -u [ n ] flag can be used to specify a one digit file descriptor unit number n on which the output will be placed. The default is 1. EXIT STATUS
The following exit values are returned: 0 Successful operation. >0 Output file is not open for writing. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
echo(1), ksh(1), attributes(5) SunOS 5.10 15 Apr 1994 print(1)
All times are GMT -4. The time now is 03:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy