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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:00:48+00:00 2026-06-04T23:00:48+00:00

Given this Bash code: TEMP=1_2 echo ${TEMP/_.*/} why does it print out 1_2 instead

  • 0

Given this Bash code:

TEMP="1_2"
echo ${TEMP/_.*/}

why does it print out 1_2 instead of 1?

I’ve also tried these, but they don’t work:

echo ${TEMP/_\.*/}
echo ${TEMP/_\\.*/}

This does work:

echo ${TEMP/_[0-9]*/}

but I want to know:

  1. Why isn’t the period acting as a wildcard?
  2. What should I use instead?
  • 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-04T23:00:50+00:00Added an answer on June 4, 2026 at 11:00 pm

    A question mark is the single-character wildcard. However, it doesn’t work like regular expressions where the asterisk is a quantifier. In Bash, in parameter expansions, an asterisk is a multicharacter wildcard.

    $ temp=1_2
    $ echo "${temp/_*}"
    1
    

    The following also work in this particular situation. See Parameter Expansion in man bash for more information regarding the differences.

    echo "${temp%_*}"
    echo "${temp%%_*}"
    

    I recommend against using all-caps variable names in order to reduce the chance of name collision with shell or environment variables.

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

Sidebar

Related Questions

I have a code like this: #!/usr/bin/env bash test_this(){ export ABC=ABC echo some output
this is probably a very stupid question; in a bash script, given the output
Given this answer: https://stackoverflow.com/a/4263048 Which is excellent, how can we be sure that out
Given this Java code: class Account { private Integer number = 0; public synchronized
Given this Java code, this outputs 0 and 4 : class A{ A() {
I have code like this in Bash : read a read b c=96.0 d=100.0
Given this HTML, CSS, and JavaScript: http://jsfiddle.net/XvqYS/3/ If you run it on Google Chrome
Given this string HELLO水 Legend: http://en.wikipedia.org/wiki/UTF-16 is 4 bytes 水 is 2 bytes Postgresql
Given this object: stdClass Object ( [customerdata] => <TPSession userid=22 CustomerId=123456LoginId=123456/><TPSession userid=26 CustomerId=1234567LoginId=1234567 />
Given this HTML: <div id=TABLE1 class=tabs> <table> <tbody datasrc=Music> <tr id=randomid>lorem</tr> <tr id=foo>lorem</tr> <tr

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.