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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:57:22+00:00 2026-06-01T22:57:22+00:00

I have a problem with my first bash script. I fill an array in

  • 0

I have a problem with my first bash script. I fill an array in for loop and when I try to get an item from it I always get the first element.

for (( i = 0; i < ${#*}; i++ )); do
hash=$(md5 -q ${@:$i:1})
modifiedNames[$i]=${@:$i:1}$hash 
done

echo ${modifiedNames[1]}

for instance if I call my script like this: ./script.sh file1 file2 i get file1[file1hash]

Thanks in advance!

  • 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-01T22:57:24+00:00Added an answer on June 1, 2026 at 10:57 pm

    $@ isn’t a real array – it’s a shell “Special Parameter”, and you need to be a bit more careful with it than other arrays.

    The reason for the behaviour you’re seeing is that the exact behaviour of the ${parameter:length:offset} syntax is special-cased when parameter is @, and the behaviour is not consistent with the behaviour you’d get if @ was a real array.

    Here’s the relevant documentation (bold emphasis mine):

    ${parameter:offset:length}

    … If parameter is @, the result is length positional parameters beginning at offset. If parameter is @, the result is length positional parameters beginning at offset. …

    The positional parameters are $0, $1, $2, …, so with this syntax it’s behaving as if $@ contained the script name ($0) as well as the parameters to the script ($1, $2, …). This is inconsistent with "$@" expanding to "$1" "$2" ..., but that’s life.

    You should be able to simplify things (and fix the script) by making a new array instead of using $@ directly, i.e.

    new_array=("$@")
    for (( i = 0; i < ${#new_array}; i++ )); do
        hash=$(md5 -q ${new_array[@]:$i:1})
        modifiedNames[$i]=${new_array[@]:$i:1}$hash 
    done
    
    echo ${modifiedNames[1]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with this script. At first I had the <div> s
i have this problem: I have created a bash script that performs some tasks.
I have a trivial for loop in a bash script which is not working
I have the following script, it reads from users.txt the first and second fields
I have a problem with a bash script. I have to use the operator
I have a problem but first i want to know if im working on
I have a problem with selecting not first selector using attributeContains jQuery('div[id*=abc]:not(:first)').hide();
i have a problem with triggering the multiple alarm at first time , here
I have a problem with a sheet that when opened for the first time,
I have a problem at hand, at first sight it looks easy and it

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.