Sh, Bash, Perl, . . .

Hi!

I'm just curious why for most scripting sh language and not bash ? So when use bash and when sh for write some script ?
 
@sniper007

POSIX sh(1) is portable, you will be able to run these scripts on FreeBSD, AIX, Solaris, HP-UX, Linux and even CYGWIN under Windows, as killasmurf86 already mentioned, many times faster then bash(1), also, you do not gain anything by writing scripts in bash(1), you only lose, if you need to create more advanced programming structures, then use python(1).
 
sniper007 said:
Hi!

I'm just curious why for most scripting sh language and not bash ? So when use bash and when sh for write some script ?

Because sh is POSIX standard shell. You want your scripts to run on any POSIX system don't you? Use Bash interactively if at all. If I was using FreeBSD I would use mksh (Mir Korn Shell) which is more or less OpenBSD version of pksh (Public Korn Shell). Lot of people like also zsh.

Korn Shell is excellent for scripting as well but there is the same issue of portability like with Bash.
 
Just to highlight:
vermaden said:
POSIX sh(1) is portable

If your script is only ever going to be run on your machine(s), and you know exactly what is (always) available, write it in anything you want.

If you want to be a good egg and contribute to the community, write it in sh(1) so your friends can use (and debug) it.
 
Oko said:
Korn Shell is excellent for scripting as well but there is the same issue of portability like with Bash.

AFAIK any script written in sh will work with mksh
However not all scripts written in mksh will work on sh, that because mksh has some extra features, that sh doesn't have..... However as I said before it's 100% sh backwards compatible.


Btw, isn't sh replaced with ksh (or was it mksh) in OpenBSD?
 
killasmurf86 said:
AFAIK any script written in sh will work with mksh
However not all scripts written in mksh will work on sh, that because mksh has some extra features, that sh doesn't have..... However as I said before it's 100% sh backwards compatible.


Btw, isn't sh replaced with ksh (or was it mksh) in OpenBSD?
Default shell on OpenBSD is OpenBSD version of public Korn Shell with custom OpenBSD patches.
Code:
# echo $SHELL                                                           
/bin/ksh
$ echo $SHELL
/bin/ksh

MirOS Korn Shell is Thorsten Glaser's version of OpenBSD version of public Korn Shell.
For scripting you of course will use sh as on any other system.
These are the shells installed on my OpenBSD machine.
Code:
$ more /etc/shells
#       $OpenBSD: shells,v 1.8 2009/02/14 17:06:40 sobrado Exp $
#
# list of acceptable shells for chpass(1).
# ftpd(8) will not allow users to connect who are not using
# one of these shells, unless the user is listed in /etc/ftpchroot.
/bin/sh
/bin/csh
/bin/ksh
/usr/local/bin/bash
BASH is installed as a dependency when I was building software using ports. As you know
some ports use BASH scripts for its configuration. Nobody in right mind would use BASH on
OpenBSD.

As of backward compatibility of pksh with sh, sure it exists but the whole point of using
Korn shell is to be able to use those extra features not present in sh.
Actually using Korn for shell scripting is not such a strange thing on proprietary Unixes.
 
vermaden said:
@sniper007

POSIX sh(1) is portable, you will be able to run these scripts on FreeBSD, AIX, Solaris, HP-UX, Linux and even CYGWIN under Windows [...]

Unfortunately Solaris' sh(1M) is not POSIX compatible. :(
 
@lme

Thanks, good to know, but I have never had any problems with scripts on Solaris, propably I did not used functionality that is out POSIX on Solaris.
 
How about csh and Tenex C-shell?

When I was designing IC's I remember it was often (together with perl) used to do all sort of configurations of the design tools of Cadence, Mentor Graphics, Synopsis, etc...
 
@Graaf_van_Vlaanderen

Do not use (t)csh for scripting, have you ever tried [CMD=""]1> 2> 2>&1 1>&2[/CMD] redirections under (t)csh?
 
vermaden said:
@Graaf_van_Vlaanderen

Do not use (t)csh for scripting, have you ever tried [CMD=""]1> 2> 2>&1 1>&2[/CMD] redirections under (t)csh?

Mostly I use only small scripts.
I remember it took me a while to find an equivalent for:

Code:
$ application 2> /dev/null &

in csh

Code:
% applicaction >& /dev/null &

But what about performance? How does csh differs from sh?
 
sh is the fastest shell,
I remember I was reading some simple benchmark (sorry, don't have link)

results were like this:
1) sh (fastest)
2) mksh
3) csh
4) bash

If my memory ain't failing bash was the slowest (if my memory is failing, that slowest was csh)
 
Back
Top