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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:48:40+00:00 2026-06-09T06:48:40+00:00

The following fails and I don’t understand why: $ echo #! the following also

  • 0

The following fails and I don’t understand why:

$ echo "#!"

the following also fails with the same error message:

$ echo "\#!"

the error message:

-bash: !": event not found

Why does it fail? How should the echo be done 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-09T06:48:43+00:00Added an answer on June 9, 2026 at 6:48 am

    The ! character is used for csh-style history expansion.

    If you do not use this feature, set +o histexpand (aka set +H) turns off this behavior. It is turned off for scripts, but often enabled for interactive use. In such cases, my personal recommendation is to turn it off permanently by adding set +o histexpand to your .bash_profile (or .bashrc if you don’t have a .bash_profile; this is more complex than I want to try to fit into a parenthetical).

    As a workaround, if for some reason you cannot or don’t want to turn off and forget about this legacy csh feature, you can use single quotes instead of double quotes — keeping in mind, of course, their different semantics. If you need to combine quoting with variable interpolation, for example, you can change

    echo "#!$SHELL"  # oops, history expansion breaks this
    

    into

     echo '#!'"$SHELL"
    

    (notice the adjacent single-quoted and double-quoted strings; after the shell is done with this, the quotes will be removed and the string #! will be output next to the value of the variable SHELL with no space between them) or a number of other common workarounds like

     printf '#!%s\n' "$SHELL"
    

    … though as remarked in a comment, even single quotes don’t necessarily prevent this from happening when they are at the end of a pipeline.

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

Sidebar

Related Questions

I don't understand why the following fails: #include<string> class Foo { public: std::string** GetStr(){return
Following code fails with a error message : t.cpp: In function `void test()': t.cpp:35:
Does anyone know why the following query fails in Derby? delete from MyTable where
The following code fails to compile (using VS2010) and I don't see why. The
I don't understand the problem, why BitmapFactory.decodeFile works fine on emulator but fails on
I don't really understand how to do transactions in DBAL I have the following
gem install fails with the following error, How do I specify the heap size
I tried using the rename database command, but it fails with the following error.
The following PHP script fails to create the directory. It will also fail to
The following script works fine on Firefox, but fails on IE8 and I'm not

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.