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 3623948
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:26:48+00:00 2026-05-18T23:26:48+00:00

I don’t have much practical programming experience. I wrote a function in shell script

  • 0

I don’t have much practical programming experience.
I wrote a function in shell script to take parameters based on whose values an external program is invoked with other parameters. (the program name is passed as a parameter to the function, $1 in this case).

Somehow I find this code shitty and would like to reduce the lines and make it more efficient. I feel like there are too many conditions here and there might be an easier way to do this. Any ideas? There has to be a better way to do this. Thanks.

Code is here

  • 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-05-18T23:26:48+00:00Added an answer on May 18, 2026 at 11:26 pm

    You can build the argument list as an array, with separate conditionals for each variable part of the list (rather than nested conditionals as you have). This is very similar to Roland Illig’s answer, except that using an array rather than a text variable avoids possible problems with funny characters (like spaces) in arguments (see BashFAQ #050) — it’s probably not needed here, but I prefer to do it the safe way to avoid surprises later. Also, note that I’ve assumed the arguments must be in a certain order — if -disp can go before `refresh, then the “all versions” parts can all be put together at the beginning.

    # Build the argument list, depending on a variety of conditions
    arg_list=("-res" "$2" "$3")    # all versions start this way
    
    if  [ "$7" = "allresolutions" ]; then
        # allresolutions include the refresh rate parameter to be passed
        arg_list+=("-refresh" "$4")
    fi
    
    arg_list+=("-disp" "$5")    # all versions need the disp value
    
    if [ "$6" = "nooptions" ]; then
        :    # nothing to add
    elif [ "$6" = "vcaa" ]; then
        arg_list+=("-vcaa" "5")
    elif [ "$6" = "fsaa" ]; then
        arg_list+=("-fsaa" "4")
    elif [ "$6" = "vcfsaa" ]; then
        arg_list+=("-vcaa" "5" "-fsaa" "4")
    fi
    
    if [ "$1" != "gears" ]; then
        # ctree has time-to-run passed as parameter to account for suitable time for
        # logging fps score. If bubble fps capture strategy is different from ctree,
        # then this if statement has to be modified accordingly
        arg_list+=("-sec" "$8")
    fi
    
    # Now actually run it
    ./"$1" "${arg_list[@]}" &>> ~/fps.log
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't have much PHP experience and I want to know how to best
Don't have much to say, just can get into the event handler. XAML: <Grid>
I don't have any experience in updating a Rails app and when I google
Don't you hate it when you have class Foobar { public: Something& getSomething(int index)
Don't they both have to convert to machine code at some point to execute
Don't overthink this - there's a very commonly used term and I ... have
Don't think my virtualhost is working correctly. This is what I have inside of
Don't ask why but I have the requirement to draw a border around certain
DON'T ASK WHY but... I have a regex that needs to be case insensitive
Don't know if this has been answered before. Have custom routes to users. If

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.