Why can't I do echo '#!/bin/sh in Freebsd? It just generates:

/bin/sh: Event not found

I tried all combos of quotes, but nothing helps. I have only Freebsd 8.4 at hand.


Despite the error message pointing the finger to /bin/sh, the problem is that your shell uses ! to insert history into the command line, and quotes do not escape the magic of !. So you need to explicitly escape the ! with a \.

For example:

echo #\!/bin/sh

You could temporarily turn off history expansions while you execute that command:

$ echo !foo
bash: !foo: event not found
$ set +H; echo !foo; set -H
  • 2
    FreeBSD does not use bash by default, but tcsh. – Roland Smith Nov 20 '16 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.