[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: question about Dash



On 2009-08-07_11:20:25, 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.

I looked at /etc/passwd on my lenny desktop and saw the root and my user,
pec, both have bash specified upon login. For me, there is no reason to
pursue this further. I was worried about maybe having to make a conversion
at an inconvenient time because bash was being removed from Debian, and
curious if there might be some benefit to me from converting. I'm now 
convinced that neither is true. 

If I ever think I could become a Debian package maintainer, learning to
work with dash will be something I have to do, but by then there will
be lots of package scripts in dash to study and copy from, I'm sure. 
And I am acutely aware that ignorance of dash is not the only condition
that I will have to remedy ;-)

Thanks.
-- 
Paul E Condon           
pecondon@mesanetworks.net


Reply to: