Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Wikipedia says that dash executes faster than bash. My question is, if I set /bin/sh to dash, will all scripts that use /bin/sh in their shebang line that was intended for bash work under dash?

share|improve this question
7  
if they don't work you should yell at the author and tell him that the #! line should be #!/bin/bash and that his scripts aren't posix compliant and thus need to be specified to run with the proper interpreter –  xenoterracide Sep 5 '10 at 3:00

2 Answers 2

up vote 10 down vote accepted

No, not all scripts intended for bash work with dash. A number of 'bashism' will not work in dash, such as C-style for loops and the double-bracket comparison operators. If you have a set of bash scripts that you want to use for dash, you may consider using checkbashisms. This tool will check your script for bash-only features that aren't likely to work in dash.

share|improve this answer
    
Ooo. Handy utility –  Michael Mrozek Sep 5 '10 at 2:36
2  
but scripts with /bin/sh in the the shebang are not intended for bash, are they now? –  hop Sep 5 '10 at 8:36
2  
@hop: They might not be intended for bash but they still may be tested only on bash. –  Maciej Piechotka Sep 5 '10 at 12:06
2  
@MaciejPiechotka Any script that uses a shebang line of #!/bin/sh but doesn't work in /bin/sh (e.g. because it was written for and only runs in bash) should be considered broken. The simplest way to fix such scripts is to replace the shebang with #!/bin/bash (or #!/usr/bin/env bash). –  jw013 Dec 16 '11 at 2:32
1  
@MaciejPiechotka You miss my point. I didn't suggest that everyone should go and now and fix all the errors in scripts on their system. No one has time for that and if they already work, there are plenty of more urgent things to do. I'm just pointing out the undeniable fact that if you write a script that depends on bash-only features you should declare it as such and not as sh. Otherwise, it simply won't work on any system that does not have sh linked to bash. The practical thing to do is to write and shebang your scripts correctly so they actually work. –  jw013 Dec 18 '11 at 3:34

Not even sh scripts are compatible with dash. Pkgsrc's bootstrap, par example.

share|improve this answer
1  
Interesting. I was under the impression that recent versions of dash are POSIX compliant. A quick check using dash -n didn't come up with any errors when run against bootstrap, but that is the most naive of tests. –  Steven D Sep 5 '10 at 6:54
    
@Steven IIRC there's one variable that dash doesn't support. Possibly more things, but the list is very small. –  xenoterracide Sep 5 '10 at 14:24
    
dash is a port of NetBSD's sh to Debian, so it seems unlikely that it doesn't work for something that has been designed to work with NetBSD's sh. Ironically, that script is not POSIX conformant but is Debian conformant since it uses local –  Stéphane Chazelas Dec 21 '12 at 10:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.