LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-13-2013, 04:30 PM   #1
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Rep: Reputation: Disabled
Entering no value intp getopts case statement?


How can you have a default action for no-value in a case-getopts?

while getopts [ $# -lt 1 ]; do
not working - see end of code:


Code:
while getopts "b:nlapdth" OPTION; do
               case "$OPTION" in  
                  b)
                     case "${OPTARG}" in 
                        full)
                            echo "LOGFLAG=false"
                            echo "FULL_LOGGING=true"
                            echo "logging_option"
                        ;;                         
                        error)
                           echo "ERRORLOGGING AS NORMAL"  
                        ;;
                  esac ;;
                              
                  n)
                             echo "restore_filename"
                             ;;                             
                  l)
                             echo "restore_latest"
                             ;;
                  a)
                             echo "listall"
                             ;;
                  p)
                             echo "project_timestamp"
                             ;;  
                  c)  
                             echo "last_contents"
                             ;;
                  d)
                             echo "RESTORE_FILES_DIRECTORY="    
                             ;; 
                  t)
                             echo "Compare"
                             ;;
                  h)
                            echo " help_action"
                            ;;
                  ?)
                            echo "HELLP HELP"
                            ;;   
                  *)
                            echo "NO ENRTY"
                            ;;
esac


while getopts [ $# -lt 1 ]; do 
                  echo -e "Please enter an option"
   echo "Usage `basename $0` for options (-b|-n|-l|-a|-p|-d|-t|-h)"
   echo "Please specify at least one of the optione listed above."
 exit
done    
done
+ getopts b:nlapdth OPTION
 
Old 03-13-2013, 04:55 PM   #2
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Batistuta_g_2000 View Post
How can you have a default action for no-value in a case-getopts?

while getopts [ $# -lt 1 ]; do
not working - see end of code:


Code:
while getopts "b:nlapdth" OPTION; do
               case "$OPTION" in  
                  b)
                     case "${OPTARG}" in 
                        full)
                            echo "LOGFLAG=false"
                            echo "FULL_LOGGING=true"
                            echo "logging_option"
                        ;;                         
                        error)
                           echo "ERRORLOGGING AS NORMAL"  
                        ;;
                  esac ;;
                              
                  n)
                             echo "restore_filename"
                             ;;                             
                  l)
                             echo "restore_latest"
                             ;;
                  a)
                             echo "listall"
                             ;;
                  p)
                             echo "project_timestamp"
                             ;;  
                  c)  
                             echo "last_contents"
                             ;;
                  d)
                             echo "RESTORE_FILES_DIRECTORY="    
                             ;; 
                  t)
                             echo "Compare"
                             ;;
                  h)
                            echo " help_action"
                            ;;
                  ?)
                            echo "HELLP HELP"
                            ;;   
                  *)
                            echo "NO ENRTY"
                            ;;
esac


while getopts [ $# -lt 1 ]; do 
                  echo -e "Please enter an option"
   echo "Usage `basename $0` for options (-b|-n|-l|-a|-p|-d|-t|-h)"
   echo "Please specify at least one of the optione listed above."
 exit
done    
done
+ getopts b:nlapdth OPTION
Got easy answer but not he best one probably:

if [ -z "$*" ]; then echo "No args";
echo -e "Please enter an option"
echo "Usage `basename $0` for options (-b|-n|-l|-a|-p|-d|-t|-h)"
echo "Please specify at least one of the optione listed above."
fi

while getopts "b:nlapdth" OPTION; do
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] GETOPTS in CASE statement Batistuta_g_2000 Linux - Newbie 1 03-13-2013 11:09 PM
[SOLVED] GETOPTS in CASE statement Batistuta_g_2000 Linux - Newbie 1 03-04-2013 06:12 PM
CASE statement oracledb0101 Linux - Newbie 3 06-13-2012 04:15 PM
Perl switch statement throwing error like Bad case statement (invalid case value?) kavil Programming 2 10-07-2010 05:50 AM
Case statement with If statement cbo0485 Linux - Newbie 4 11-07-2007 09:05 PM


All times are GMT -5. The time now is 08:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration