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

Re: question about Dash



In <[🔎] 20090807072350.GA17035@samad.com.au>, Alex Samad wrote:
>On Thu, Aug 06, 2009 at 11:24:18PM -0600, Paul E Condon wrote:
>> Recent mentions of dash on this list prompted me to try to learn more
>> about it.
>> I feel uncomfortable being so totally ignorant about an impending change
>> in Debian. I want to read something, but can't find anything to read.
>
>from my understanding
>
>dash is a posix compliant shell
>bash isn't - well it has whats called bash-isms

Both are POSIX compliant as far as I can tell.

>all scripts that work in
>sh should work in dash and bash
>dash should work in bash

This means that if you write a script using only POSIX features it will work 
on both shells.

>not all bash scripts will work in sh or dash

However, there are many, many bashisms (some of which are also kshisms) that 
work in bash but are NOT POSIX features.  Dash does not implement all of the 
bashisms (or kshisms), so it cannot run scripts using them.

For many years, /bin/sh was bash on Debian.  Because of this many users, 
maintainers, and developers got used to using bashisms even in scripts that 
were executed by /bin/sh.  (Bash does turn off some features when invoked as 
/bin/sh, but not many.)

Even users, maintainers, and developers that came from other OSes were used 
to some of these features.  The Korn Shell--ksh--has been the default user 
shell on many UNIXes, and sometimes was even used as /bin/sh.

As such, the vast majority of shell scripts are NOT POSIX compliant, so even 
with a POSIX shell as /bin/sh many scripts break.

>the first line is used to invoke a program to process the script for
>example
>
>there is name for this, but I can't remember it right now.

The "#!" is colloquially referred to as a shebang.[1]  In all known 
implementations of POSIX, "#!" as the first two characters in a shell script 
indicates that the rest of the line is used as the command interpreter.  
Implementations vary in how they do path lookup on this and how whitespace 
is handled and if/when the line is truncated.[2]

>Bashism - off the top of my head, I believe things like $(( - arithmetic
>expressions

three=$((1 + 2))
nine=$((three * 3))
twelve=$((38 / $three))

is a valid SUSv2 shell script.  Not sure about ISO POSIX.

"local" is a bashism.  ("local" is also a "dashism"; Debian policy requires 
/bin/sh to support lexically scoped environment variables.)
Array variables are a kshism inherited by bash
"<<<" is a bashism
print is a kshism inherited by bash

There are many others.  The Open Group publishes the Single Unix 
Specification (SUS), available free-of-charge from their website after a 
single registration form.  As holders of the UNIX trademark, they determine 
what is and what isn't "UNIX".  Part of being "UNIX" is conformance to the 
Single Unix Specification, which started as (and still is) POSIX plus 
extensions.  That document will tell you exactly what features you can 
expect from a UNIX shell (usually /bin/sh) -- anything not listed should 
normally be avoided (or you should specify what shell you want).
-- 
Boyd Stephen Smith Jr.           	 ,= ,-_-. =.
bss@iguanasuicide.net            	((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy 	 `-'(. .)`-'
http://iguanasuicide.net/        	     \_/

[1] Unless you run the Linux distribution "#!" which they pronounce as 
crunch-bang.

[2] Oddly enough, using a #! line makes any shell script have "undefined" 
behavior and thus be--strictly speaking--POSIX non-compliant.  All known 
implementations of the POSIX standard use the #! line similarly, so 
#!/bin/sh works on all of them.

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: