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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:16:02+00:00 2026-05-31T15:16:02+00:00

the code is: echo -n Enter the number you want to search for read

  • 0

the code is:

echo -n "Enter the number you want to search for"
read number1
for i in `seq 1 $N`
do
  temp= $number1
  if [ temp -eq ${array[$index]} ]
  then 
    temp= $index
  fi
done

echo " The position is" $temp

i donot get an output for this
just the position is and no number.
What am i doing wrong?

  • 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-31T15:16:03+00:00Added an answer on May 31, 2026 at 3:16 pm

    There are a few big problems here.

    Whitespace in assignment. One problem is that these lines:

      temp= $number1
    
        temp= $index
    

    need to be like this instead:

      temp=$number1
    
        temp=$index
    

    This is because in Bash, something like this:

    varname=value command
    

    runs the command command with the environment variable varname set to value. In your case, this:

    temp= $number1
    

    tries to run the command $number1 with the environment variable temp set to the empty string.

    Reuse of temporary variable. Another problem is that this line:

      temp=$number1
    

    is run on every pass through the loop; so even if temp had previously been set to an appropriate array index, the above will discard that value and replace it with the number that the user had entered. Really, you should just remove this line, and use $number1 directly when you need it.

    Variable-name mismatch. Another problem is that this line:

    for i in `seq 1 $N`
    

    uses i for the loop variable, but these lines:

      if [ temp -eq ${array[$index]} ]
      then 
        temp= $index
    

    use index. Needless to say, these need to match.

    Unexpanded variable. This line:

      if [ temp -eq ${array[$i]} ]
    

    was surely meant to be this:

      if [ $temp -eq ${array[$i]} ]
    

    (expanding the variable $temp instead of using the string 'temp'); but in light of the above, it should now be:

      if [ $number1 -eq ${array[$i]} ]
    

    Array indices. Array indices start at zero; so if N is the number of elements in the array, then you need to iterate from 0 to N-1. So, this:

    for i in `seq 1 $N`
    

    needs to be this:

    for i in `seq 0 $((N - 1))`
    

    Though I actually think you should get rid of N entirely, and use ${#array[@]} (which is a Bash notation meaning “the number of elements in array) instead:

    for i in `seq 0 $((${#array[@]} - 1))`
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code number=1 if [[ $number =~ [0-9] ]] then echo matched fi
The code below takes an array value, if it's key exist it should echo
I'm using following peace of code to output an array: echo ======output without array_unique=====;
I want to allow the user to enter a coupon number in order to
#!bin/bash echo enter your password : read password passlength=$(echo ${#password}) if [ $passlength -le
I have this PHP code echo '<a href=# onclick=updateByQuery(\'Layer3\', ' . json_encode($query) . ');>Link
I'm using this code now echo $form->input('username'); How do I make sure the label
im trying to echo mediaplayer embed code with IF statement. is there any way
I have this code while($row = mysql_fetch_row($result)) { echo '<tr>'; $pk = $row[0]['ARTICLE_NO']; foreach($row
In the code below, the echo at the top returns true, but the echo

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.