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

  • Home
  • SEARCH
  • 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 8690253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:51:47+00:00 2026-06-12T23:51:47+00:00

Why does this command line work: $ output=’Irrelevant’; if [[ $output =~ Something ]];

  • 0

Why does this command line work:

$ output='Irrelevant'; if [[ $output =~ Something ]]; then echo "I found something in the output." ; fi

And this one give me a strange parse error?

$ output='Irrelevant'; if [[ $output =~ Something ]]; then echo "I found something in the output!" ; fi
-bash: !": event not found

The only change from the first version is that the sentence to be echoed inside quotes ends with an exclamation mark. Why does Bash give me that error in the second version?

In case it matters, this is the output from bash --version:

GNU bash, version 4.2.24(1)-release (x86_64-pc-linux-gnu)
  • 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-12T23:51:48+00:00Added an answer on June 12, 2026 at 11:51 pm

    You can wrap the string in single quotes instead of double quotes.

    The exclamation point invokes the very useful history expansion function described in the bash manual.

    History expansions are introduced by the appearance of the history expansion character, which is ! by default. Only \ and ' may be used to escape the history expansion character.

    For instance, to execute the last command that started with the word mysql type this:

    !mysql
    

    or to execute the last command containing the word grep, type this:

    !?grep
    

    The bash manual also documents the syntax of the history expansion operators.

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

Sidebar

Related Questions

Why this curl command does not work in CMD. It should downlaod a html
Does this look like it should work? I'm wanting to generate directions from one
Trying to get Amazon's EC2 command line tools to work. This is what my
Does PowerShell have an equivalent to this command construct from sh (and derivatives): $
Does anyone know what this warning means? It is followed by the error: Command
Does this work well as a Singleton in actionscript? i.e. are there any gotchas
I have a set of piped commands that work on the command line, but
A command-line program outputs a list of file paths. I pipe the output to
I am inputting this text file into the command line: 800 5 10 800
I am writing a command line tool to convert Markdown text to html output,

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.