Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9057213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:23:52+00:00 2026-06-16T14:23:52+00:00

I have a script with a long list of OPTIONAL arguments. some have associated

  • 0

I have a script with a long list of OPTIONAL arguments. some have associated values.

Such as:

.script --first 2012-12-25 --last 2012-12-26 --copy --remove
.script --first 2012-12-25 

Thus the following case statement:

for arg in "$@"
do
    case $arg in
        "--first" )
           START_DATE=$arg;;
        "--last" )
           END_DATE=$arg;;
        "--copy" )
           COPY=true;;
        "--remove" )
           REMOVE=true;;

# ... and so on
   esac
done

My problem:

that needs a increment $arg+1 type statement to get the following arg (in some cases).

How is that possible?

I’m also happy to do a substring such .script --first2012-12-25 --last2012-12-26

and not sure how to proceed there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:23:53+00:00Added an answer on June 16, 2026 at 2:23 pm

    getopts cannot have optional arguments it seems. otherwise great.

    my solution

    loop the $@ and setting a variable equal to x=$arg
    do the case switch on that variable (rather than arg)

    that worked fine for arguments of the type --startdate 2012-12-25 --enddate 2012-12-29

    but did not work for --remove that has no following argument.

    therefore tack on stuff (unlikely argument) onto the arg string.

    leaving the following

    argc="$@ jabberwhocky" 
    echo $argc
    x=0
    # x=0 for unset variable
    for arg in $argc
    do
       case $x in
            "--start" )
              STARTDATE=$arg ;;
            "--end" )
              ENDDATE=$arg ;;
            "--copy" )
              COPY=true;;
            "--remove" )
              REMOVE=true;;
    

    … and so on….

        esac
        x=$arg
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ksh script that returns a long list of values, newline separated,
I have a VBA script that inserts long strings into Excel cells. In some
I have a long-ish script to do some data analysis, and it has to
I have a long list of arrays which contain values. I'm trying to write
I have a long list elements <li> in my html code: <li class=pl1><a href=#>some</a></li>
I have a long list of domain names which I need to generate some
With my database upgrade scripts, I typically just have one long script that makes
I have a script that is taking too long to run and I have
I have some long running scripts with breaks requiring input/interaction to continue but when
I have script file where a command is stored in a variable First i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.