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

  • Home
  • SEARCH
  • 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 9024271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:57:53+00:00 2026-06-16T05:57:53+00:00

I am trying to optimize my shell script a bit and want to be

  • 0

I am trying to optimize my shell script a bit and want to be able to display the contents of an array based on user input that is stored in a variable:

Here is an excerpt from my script

logArr( firstLogs  secondLogs  thirdLogs  fourthLogs)
firstLogs=( a  b  c  d  e )
secondLogs=( f  g  h  i  j )
thirdLogs=( k  l  m  n  o )
fourthLogs=( p  q  r  s  t )


echo "Please enter a top-level directory for the logger..."
count=1
for i in "${logArr[@]}"
do
    echo "$count: $i"
    count=`expr $count + 1`
done
read logDir
logDir=`expr $logDir - 1`
logDir=${logArr[$logDir]}

So at this point I have the user input set in the variable $logDir. Is there a way to use that to display the values of the respective array, i.e. if they chose secondLogs I want to then display the contents of the secondLogs array without having to use and if elif elif elif scenario if possible. I have tried some eval stuff but I cant seem to make it work.

Any help is appreciated.

EDIT: If my request is too vague let me know and I am happy to clarify anything. Thanks!

  • 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-16T05:57:54+00:00Added an answer on June 16, 2026 at 5:57 am
    logArr=(firstLogs secondLogs thirdLogs fourthLogs)
    firstLogs=(a b c d e)
    secondLogs=(f g h i j)
    thirdLogs=(k l m n o)
    fourthLogs=(p q r s t)
    echo 'Please enter a top-level directory for the logger...'
    
    select logDir in ${logArr[*]}
    do
      break
    done
    
    set $logDir[*]
    echo ${!1}
    

    Output

    Please enter a top-level directory for the logger...
    1) firstLogs
    2) secondLogs
    3) thirdLogs
    4) fourthLogs
    #? 2
    f g h i j
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to optimize some basic jquery script that traverses and hides/shows some
I'm trying to optimize some code that takes some test data stored in CSV
I'm trying to optimize my site, in order to do that I want to
I'm trying to optimize my code using Neon intrinsics. I have a 24-bit rotation
I'm trying to optimize the size of my Delphi classes so that they take
I'm trying to optimize a set of stored procedures. These stored procedures are on
I'm trying to optimize some of the user facing parts of my app by
I'm trying to optimize a stored procedure I'm maintaining, and am wondering if anyone
We are currently trying to optimize the performance of an ASP.NET based website which
I was trying to optimize a program I'm tinkering with, when I noticed that

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.