I have tried the escape character but it doesn't seems works with !. I need this to auto-configure packages using scripts.
Asked
Active
Viewed 1.7k times
3 Answers
13
!
is magic in a default interactive bash session, but not in scripts (set +H
to disable in an interactive prompt). In any case:
echo '#!/bin/bash'

that other guy
- 116,971
- 11
- 170
- 194
-
That is, using single quotes you avoid variable expansion. – fedorqui Apr 01 '14 at 22:16
1
printf should work too:
printf '#!/bin/bash\n'

Avi Das
- 1,725
- 1
- 13
- 19
-
1`printf` is beside the point. The issue is the shell's interpreting of the hashmark, not which command it's passed to. (Also, if you're going to use `printf`, you'll want to include a `\n` at the end, or your shebang line will run into the next line printed. – Adam H. Peterson Apr 01 '14 at 23:48
-
-
-
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – ElmoVanKielmo Apr 02 '14 at 07:18
-
@ElmoVanKielmo It does provide an answer to the question, though the issue OP was having wasn't really related to `echo/printf` so it's basically the same as [that other guy's](http://stackoverflow.com/a/22797555/3076724) – Reinstate Monica Please Apr 02 '14 at 23:26
-
@BroSlow this was a review and as you probably know - messages are predefined in that case. – ElmoVanKielmo Apr 03 '14 at 05:25