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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:38:59+00:00 2026-05-29T08:38:59+00:00

I found some strange behavior in PowerShell surrounding arrays and double quotes. If I

  • 0

I found some strange behavior in PowerShell surrounding arrays and double quotes. If I create and print the first element in an array, such as:

$test = @('testing')
echo $test[0]

Output:
testing

Everything works fine. But if I put double quotes around it:

echo "$test[0]"

Output:
testing[0]

Only the $test variable was evaluated and the array marker [0] was treated literally as a string. The easy fix is to just avoid interpolating array variables in double quotes, or assign them to another variable first. But is this behavior by design?

  • 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-29T08:39:00+00:00Added an answer on May 29, 2026 at 8:39 am

    So when you are using interpolation, by default it interpolates just the next variable in toto. So when you do this:

    "$test[0]"
    

    It sees the $test as the next variable, it realizes that this is an array and that it has no good way to display an array, so it decides it can’t interpolate and just displays the string as a string. The solution is to explicitly tell PowerShell where the bit to interpolate starts and where it stops:

    "$($test[0])"
    

    Note that this behavior is one of my main reasons for using formatted strings instead of relying on interpolation:

    "{0}" -f $test[0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found some rather strange behavior... Here is how to replicate the problem: Create
I just found some strange behavior of database's order by clause. In string comparison,
I'm working on a heavily data-bound Win.Forms application where I've found some strange behavior.
I found some strange behavior when using nested Spring transactions: when, in the same
I'm hacking my way through learning Flex and have found some strange behaviour. When
Debugging some finance-related SQL code found a strange issue with numeric(24,8) mathematics precision. Running
i found some articles, some projects to create thumbnail of a video, using ffmpeg.exe,
I found a strange behavior of chomp in Perl and I am unable to
Good day, everyone. I found strange behavior within ASP.NET engine when it handles non-existent
So I noticed some strange behavior when using a subclass of a NSManagedObject 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.