On Fri, Aug 07, 2009 at 11:20 +0300, Andrei Popescu wrote: > On Thu,06.Aug.09, 23:24:18, Paul E Condon wrote: > > Recent mentions of dash on this list prompted me to try to learn more > > about it. I googled and learned that it has a different convention for > > indicating that a file is a script that should be processed by > > dash. This affects only the first line of a script. > > The first line in a script *should* indicate what program is to be used > to interpret it. The most common script interpreter on a GNU/Linux > system is a "Bourne shell" (sh) *clone*. Both bash and dash are such > clones. The downside to bash (the "Bourne again shell") is that it has > a *lot* of extensions, and even worse, it's using them even if called as > 'sh' (yes, it can tell if it was invoked as 'sh' or 'bash'). > > Dash ("Debian Almquist SHell") also has two or three extensions, but > these are specifically allowed by Debian Policy, it is about 10 times > smaller than bash and significantly faster. > > Of course, you probably won't notice the speed difference on a three > line script. > > > Is this the only difference in coding scripts? I know it is said to be > > smaller and faster, which is good, but are there things that need to > > be changed in a bash script, after the first line, in order to make it > > into a proper dash script? What are they? Where can I learn what to > > change in my scripts? Or is it just smaller and faster with no > > conversion pain? > > If your scripts do not use bash extensions (bashisms) and the shebang is > > #!/bin/sh > > then just install dash, let it take over the /bin/sh symlink (run > 'dpkg-reconfigure dash' if you're on lenny) and enjoy the additional > speed. I've been doing this for years without ill effects. You will also > notice if any 'sh' scripts are using bash extensions ;) > > A safer way to do this is to use the 'checkbashisms' script in the > package 'devscripts' first. Beware though that 'checkbashisms' is not > 100% sure. In the end you won't know unless you check the scripts > yourself (if you know what to look for) or just try to run them with > dash: > > /bin/dash my_custom_script.sh > > If you do find a script that doesn't work with dash (but does with bash) > you can: > > 1. try to rewrite it in 'sh' > 2. change the shebang to point to 'bash' > > Option 1. is good if you want to make your scripts more portable. > Option 2. is easier, especially on complex scripts. > > BTW, this talk about 'dash' vs. 'bash' is NOT about the user shell (the > shell that is specified in /etc/passwd and started on login to the > console or when you open a terminal emulator). As a user shell dash is > NOT apropiate, unless you are running some embedded system with very > little storage/memory. > > Regards, > Andrei > -- > If you can't explain it simply, you don't understand it well enough. > (Albert Einstein) I fully agree with Andrei in what he is saying (including his .sig :) If interested, you might also whant to look at: http://en.wikipedia.org/wiki/Bourne_Shell for historical background and more (even Bourne's macros making C look like algol68). Regs Siggy -- Please don't Cc: me when replying, I might not see either copy. bsb-at-psycho-dot-informationsanarchistik-dot-de or: bsb-at-psycho-dot-i21k-dot-de O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
Attachment:
signature.asc
Description: Digital signature