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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:30:47+00:00 2026-06-17T09:30:47+00:00

It is very interesting that if you intend to display 0_1 with Bash using

  • 0

It is very interesting that if you intend to display 0_1 with Bash using the code

x=0
y=1
echo "$x_$y"

then it will only display

1

I tried echo "$x\_$y" and it doesn’t work.

How can I echo the form $x_$y? I’m going to use it on a file name string.

  • 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-17T09:30:47+00:00Added an answer on June 17, 2026 at 9:30 am

    Because variable names are allowed to have underscores in them, the command:

    echo "$x_$y"
    

    is trying to echo ${x_} (which is probably empty in your case) followed by ${y}. The reason for this is because parameter expansion is a greedy operation – it will take as many legal characters as possible after the $ to form a variable name.

    The relevant part of the bash manpage states:

    The $ character introduces parameter expansion, command substitution, or arithmetic expansion.

    The parameter name or symbol to be expanded may be enclosed in braces, which are optional but serve to protect the variable to be expanded from characters immediately following it which could be interpreted as part of the name.

    When braces are used, the matching ending brace is the first } not escaped by a backslash or within a quoted string, and not within an embedded arithmetic expansion, command substitution, or parameter expansion.

    Hence, the solution is to ensure that the _ is not treated as part of the first variable, which can be done with:

    echo "${x}_${y}"
    

    I tend to do all my bash variables like this, even standalone ones like:

    echo "${x}"
    

    since it’s more explicit, and I’ve been bitten so many times in the past 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found a very interesting question. When I'm using following code: int main() {
I ran across some very interesting code that makes me wonder about what bool
I just stumbled over a very interesting problem. Giving the following code: using System;
I saw very interesting example of using html5 css3 and javascript that is amazing,
I haven't tried D yet, but it seems like a very interesting language that
I found a very interesting memory leak detector by using Visual C++. http://www.codeproject.com/KB/applications/visualleakdetector.aspx I
I've seen a very interesting post on Fabio Maulo's blog. Here's the code and
Here is one very interesting problem. I am using SQL Server 2008. I have
I recently ran against a very interesting site that expresses a very interesting idea
I have a very interesting issue with only specific IE implementations. I have an

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.