Bourne is not bash, or: Read, echo, and backslash
shebang.brandonmintern.com
shebang.brandonmintern.com
echo 'abcdefghijklm\nop
123456789' | awk '{print}' #!/usr/bin/env python
Since python is not a POSIX-specified utility, it might be anywhere on the user's PATH. Using the env trampoline (it is guaranteed to be available at /usr/bin/env) will allow your script to work on any POSIX system that has Python installed and on the PATH.In a brief search, I wasn't able to find a canonical location of awk defined in POSIX, so it might be necessary to use env for that, too.
#!/usr/bin/env python
also ensures your scripts look for the virtualenv python when virtualenv is activated, but the system python when virtualenv is deactivated.Using /usr/bin/env is common practice, but not standardized in any way. Also, POSIX does not specify the '#!' syntax, and only documents the original mechanism of running shell scripts (execl/vp() passes anything that is not understood by kernel to sh).
Small nitpick with the ".sh" - it's false advertising once it's become a bash script; but don't just go to ".bash", rather just drop it and it's set. And soon, otherwise users write other programs depending on the script's name - with ".sh", then you reimplement in python/perl and bemoan that your alleged shell script is now a wolf in sheep's clothing, then reimplement it in C - and that ".sh" is still stuck there, a strange historical note that now undermines the entire original reason for putting an extension on it at all.
Commands shouldn't have extensions, ever, on Unix or its variants. Unix has magic numbers and interpreter directives, DOS has extensions and the ability to ignore them when looking up commands ... never the twain should meet.
Just saying'. ;-)
... this wouldn't be a problem if Ubuntu hadn't run away with its own default shell...
And we haven't considered the confusion that Bash, when invoked as "/bin/sh" behaves differently than both the Bourne shell and Bash invoked as "/bin/bash".
Instead of cramming things in /etc/profile (which really should only be about environment variables, where ~/.bashrc should pick most of them up from the parent process), just having ~/.bash_login read ~/.bashrc solves getting all your interactive bash startup commands into one file (assuming the /etc/skel/.* is used during account creation so users don't have to set that up themselves).
If you want to invoke the echo executable, specify it explicity (/bin/echo). Limitations on POSIX limitations posted by others noted.
1. POSIX /bin/echo does not recognize any options other than "-n", and "-n" is "implementation-defined". [0] So you end up right back at the same problem.
2. I highly recommend using built-ins where possible. Invoking /bin/echo instead of using echo involves copying a string into an argument vector, setting argc, loading /bin/echo, attaching std file descriptors, and forking. All of this to print a string to stdout.
It's much better to explicitly specify the behavior you want by invoking the appropriate interpreter, or to use /bin/sh while being sure to stick to POSIX-compliant functionality (e.g. printf).
[0] http://pubs.opengroup.org/onlinepubs/009695399/utilities/ech...
# dpkg-reconfigure -p low dash
Neat unix trivia article but don't blaspheme Debian... dpkg-reconfigure -p low dashOn a related note set the debconf priority to low so that you always know the dpkg decisions that go into the creation of your system. That way you are not ignorant like the doubters above...
zokier@galleria:~$ uname -a
Linux galleria 2.6.32-5-686 #1 SMP Thu Nov 3 04:23:54 UTC 2011 i686 GNU/Linux
zokier@galleria:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 6.0.3 (squeeze)
Release: 6.0.3
Codename: squeeze
zokier@galleria:~$ which sh
/bin/sh
zokier@galleria:~$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Jan 1 11:38 /bin/sh -> dash
zokier@galleria:~$ debconf-show dash
debconf: DbDriver "passwords" warning: could not open /var/cache/debconf/passwords.dat: Permission denied
* dash/sh: true
zokier@galleria:~$ dpkg-reconfigure -p low dash The most common use is "debconf-show packagename", which displays all items in
the debconf database owned by a given package, and their current values.
Questions that have been asked already are prefixed with an '*'.
True means link /bin/sh to dash.Its awesome to get downvoted for being correct...
dpkg-reconfigure -p low dash