Reply
Thread Tools
Posts: 3,841 | Thanked: 1,079 times | Joined on Nov 2006
#11
It's considered "best" to always use /bin/sh, as that will work with whatever sh-compatible shell that's native to the system. Unless you actually need bash-shell extensions (it can do a bit more than good old sh).

To find out if you have bash you can use several methods, e.g.
Code:
which bash
or, if you are already executing a bash-lookalike (e.g. ash) you can do
Code:
type bash
On my tablet there's no bash, so try 'ash' instead with the above commands. It should output /bin/ash.
__________________
N800/OS2007|N900/Maemo5
-- Metalayer-crawler delenda est.
-- Current state: Fed up with everything MeeGo.
 

The Following 3 Users Say Thank You to TA-t3 For This Useful Post:
Banned | Posts: 57 | Thanked: 2 times | Joined on Jul 2008
#12
Hi,

I installed bash for OS2007HE to access arrays.
Writing first shell script was a nightmare for me
as maemo has small screen I edited shell files on PC running Win XP
than saved a file as text .sh , moved to memory card,
moved to /home/user
chmod and tried to use,
forgetting to dos2unix.exe it first.

Installed gainroot, mc
and today try to edit basic shell script in mc's editor.

Installed dialog too to have some DOS-like interaction + menu
to run test shell scripts in sh and bash.

darius
Originally Posted by dfinch View Post
Since sh worked I presume I should continue with this at the begining of scripts?
How would I verify presense of bash? (I certainly have not loaded 'it' deliberatley)
 
dfinch's Avatar
Posts: 362 | Thanked: 82 times | Joined on Jan 2008
#13
Originally Posted by TA-t3 View Post
It's considered "best" to always use /bin/sh, as that will work with whatever sh-compatible shell that's native to the system. Unless you actually need bash-shell extensions (it can do a bit more than good old sh).

To find out if you have bash you can use several methods, e.g.
Code:
which bash
or, if you are already executing a bash-lookalike (e.g. ash) you can do
Code:
type bash
On my tablet there's no bash, so try 'ash' instead with the above commands. It should output /bin/ash.
Thanks, no bash found but 'which ash' found bin/ash

Most ppl seem to be saying use bin/sh so for what I'm doing this looks to be the best approach right now.

Again, thanks to all.
__________________
N810, OS 2008 5.2008.43-7 (Diablo)
Nobody can accuse me of not contradicting the invalid arguments of the opposition!
Derek
 
Benson's Avatar
Posts: 4,930 | Thanked: 2,272 times | Joined on Oct 2007
#14
On early UNIX, (when the Bourne shell was the most advanced Bourne-compatible shell), it lived as /bin/sh.
Now there are at least three Bourne-compatible shells in common use:
  • ash - Almquist SHell; this was originally a clone of an some Bourne shell (sysvr4?), and deliberately lacks extended features. (There's several variants; we have busybox ash by default.)
  • bash - Bourne Again SHell; GNU clone of bash with a truckload of features.
  • ksh - Korn SHell; This is another classic UNIX shell, designed with a focus on scripting, as well as enhanced interactive use from csh, and backwards compatibility to sh. (There's several variants here, too...)
  • zsh; less commonly used, but attempts to incorporate the benefits of bash, ksh, and tcsh. Most notable use is probably Darwin and derivatives.
On most modern UNIXen, there's no binary at /bin/sh; it's a symlink to some Bourne-compatible shell (usually with extensions). But it's always there, and should always be nominally compatible. So by writing scripts using a portable subset of what your /bin/sh knows, and using /bin/sh as an interpreter, your script can work on any UNIX.

Sven Mascheck has some more info on portability, and on shell history in general, at his site. Good reading.

But bottom line is: shebang for /bin/sh, and if it runs on ours (busybox ash), it's a decent bet it'll work everywhere else.
 

The Following 3 Users Say Thank You to Benson For This Useful Post:
Posts: 80 | Thanked: 22 times | Joined on Apr 2008 @ South Florida
#15
Yup - Benson's got it right.

Write your script using basic sh (available on almost every unix) - and then it will be portable across many.

I've been doing it this way for years - moving scripts from solaris/sys 5/linux/bsd and even the pc with the gnu tools.

Fix the paths - and then go!
 
Reply


 
Forum Jump


All times are GMT. The time now is 15:54.