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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:08:50+00:00 2026-05-28T22:08:50+00:00

Just pesuocode but this is essentially what I would like to do. Array=(1 Linux

  • 0

Just pesuocode but this is essentially what I would like to do.

Array=("1" "Linux" "Test system"
       "2" "Windows" "Workstation"
       "3" "Windows" "Workstation")


echo "number " ${array[search "$1"]} "is a" ${array[search "$1" +1]} ${array[search "$1" +2])}

Is this possible with bash? I could only find info on search and replace. I didn’t see anything That would return and index.

  • 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-28T22:08:50+00:00Added an answer on May 28, 2026 at 10:08 pm

    Something like that should work:

    search() {
        local i=1;
        for str in "${array[@]}"; do
            if [ "$str" = "$1" ]; then
                echo $i
                return
            else
                ((i++))
            fi
        done
        echo "-1"
    }
    

    While looping over the array to find the index is certainly possible, this alternative solution with an associative array is more practical:

    array=([1,os]="Linux"   [1,type]="Test System"
           [2,os]="Windows" [2,type]="Work Station"
           [3,os]="Windows" [3,type]="Work Station")
    
    echo "number $1 is a ${array[$1,os]} ${array[$1,type]}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question has been brought up many times, but I'd like to ask it
I'm just trying to time a piece of code. The pseudocode looks like: start
So maybe I have this all wrong, but I'm sure there is a way
So basically what I'm trying to do is make something like this: http://store.kapit.biz/demo/treemap/prod/index.html# I've
I'm just getting started with Python but already have found it much more productive
My WCF Service in C# looks like this. [ServiceContract] public class MySecretService { [OperationContract]
I've got a simple Visual Basic 2008 Express Edition form which looks like this:
I'm wondering if this is possible. I have html like so: <p> <font face=Georgia>
First off, this is homework, but I am simply looking for a hint or
Sorry, it's a long one, but I'm just explaining my train of thought as

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.