getopts and "priority level" for args


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getopts and "priority level" for args
# 1  
Old 03-29-2005
getopts and "priority level" for args

Hi, I use getopts in this way:
Code:
while getopts ":d:f:crapv" Option
do
  case $Option in
    d     ) BACKUP_DIR="$OPTARG";echo $BACKUP_DIR;; #echo fot test
    c     ) compress_file;;                     
    r     ) remove_file;;                       
    a     ) remove_file && compress_file;;
    p     ) print_file;;                        #for test
    f     ) echo "Extension test";;
    v     ) echo $APP_VERSION;;
    \?    ) echo "$USAGE" exit 1;;
    *     ) echo "$USAGE" exit 1;;
  esac 
done

If I run the script with
Code:
./myscript -d /home/marco/temp/ -p

it's all ok but if I run the script in this other way
Code:
myscript -p -d /home/marco/temp/

the BACKUP_DIR var isn't set. There is a way to check if "-d" (for example) is in the command line option and if it's true do -d operation before the other? Or there is a way to don't execute the operation if there is a -d option in the command line but it isn't the first option?
# 2  
Old 03-29-2005
You need to do something like this. Before your option loop do:
printfile=0
Inside the loop:
p) printfile=1
And after the loop:
((printfile)) && print_file
or
if ((printfile)) ; then
print_file
fi
# 3  
Old 03-29-2005
Mmm ok, good idea Smilie I will try in this way. Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to run root level command , if user has "su -" permission in sudoers provided?

I am looking t run root level command on multiple servers, but all servers have only "su - " permission available in sudoers. please help me if any way that I can run command using help of "su -" My script for hosts in `cat hosts.txt`; do echo "###########################Server Name-... (5 Replies)
Discussion started by: yash_message
5 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

Rsync is not working at root "/" level between two servers

copying daily changes from serverA to serverB using rsync(solaris8, v2.6.2) at root folder level. serverA: cd / rsync -a -vv --delete --checksum --sparse --stats --dry-run --exclude /tmp/ --exclude /proc/ --exclude /devices/ . root@<IP of ServerB>:/ This is generating mainly three debug... (0 Replies)
Discussion started by: kchinnam
0 Replies

4. 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

5. AIX

Missing base level fileset for "bos.loc.utf.EN_US"

I need to install "bos.loc.utf.EN_US" in AIX ( version 6100-06-05-1115). I found the right bff U845493 and I smitty to install it and encountered the "missing requisites" error in which missing the "base level fileset" . And I couldn't find this fileset from the Internet for long. Do any one able... (2 Replies)
Discussion started by: bshcheng
2 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Solaris

How to activate "high" priority queues for codine (Sun Grid Engine) under solaris 10

How to activate "high" priority queues for codine (Sun Grid Engine) under solaris 10? What are the steps? (0 Replies)
Discussion started by: ionrivera
0 Replies

8. Shell Programming and Scripting

foreach loop using a "*" for args

have a script that copies a file to a bunch of hosts. works great with a single file. How do I make it copy all files in a source directory? or a *txt pattern, or anything using a * ??? name of script: cp2all #!/bin/csh foreach host ( host1 host2 host3 host4 host5 host6 host7) rcp $argv... (1 Reply)
Discussion started by: ajp7701
1 Replies

9. UNIX for Dummies Questions & Answers

No utpmx entry: you must exec "login" from lowest level "shell"

Hi I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message No utpmx entry: you must exec "login" from lowest level "shell" :confused: What i want is: open various... (0 Replies)
Discussion started by: peterpan
0 Replies
Login or Register to Ask a Question