LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-02-2007, 03:58 PM   #16
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40

I read a white paper a few years back that explained at the time why batch programming should be done in sh (bash). Because in tcsh and ksh, while having perhaps richer instruction sets than plain old sh (bourne shell) the behaviour of some constructs tended to differ slightly between the batch and interactive execution of some scripts. Sh was simple, but considered very safe for batch. Just in case, and while your assembled audience awaits you posting the awk version info.

PAix
 
Old 11-03-2007, 12:14 AM   #17
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
Many people think that shell scripts should be written for sh, for portability.
OTOH, I learned shell scripting in bash & am not about to give up its richness.
If it ever (doubtful) gets to a point that someone really needs to run something of mine on a system that doesn't have bash,
they have 3 choices:
  • Install bash.
  • Do without.
  • Hire my friend Willie to re-write it.
 
Old 11-05-2007, 03:33 AM   #18
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
I've never (in all my days) had any trouble running ksh in batch mode.

An annoying thing about linux is that even if you do a
#!/bin/sh it actually runs bash and it's not properly compatible.

so you get a linux bod wiriting a /bin/sh script that won't run on your solaris box
unless you swap it to /bin/ksh.
and when you explain it to them they don't get it.

Another reason is you'll find that on unix boxes the /bin/sh would be statically linked
so if all goes pear shaped it's more likey to work than other shells
 
Old 11-05-2007, 09:04 AM   #19
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Quote:
An annoying thing about linux is that even if you do a
#!/bin/sh it actually runs bash and it's not properly compatible.
Uhh no. This is only a problem (feature explained in man bash maybe?) of BASH.

Code:
aha@debian$ echo $0
bash
aha@debian$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2007-10-01 12:06 /bin/sh -> dash
aha@debian$ cat listf 
#!/bin/bash
 for t in files links directories; do echo $t:`find . -type ${t:0:1} | wc -l`; done 2> /dev/null
aha@debian$ ./listf 
files:60
links:3
directories:2
aha@debian$ sed -i 's/bash/sh/' listf 
aha@debian$ ./listf 
./listf: 1: Syntax error: Bad substitution
This shows that /bin/sh was launched as requested.
 
Old 11-05-2007, 09:13 AM   #20
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
ok, try this and I'll believe you, much simpler...

granted on cygwin, I'm at work, but...

Code:
$ uname -a
CYGWIN_NT-5.1 BTG142169 1.5.23(0.156/4/2) 2006-12-19 10:52 i686 Cygwin
$ /bin/sh
$ export X=Y
Code:
billym.>uname -a
SunOS primadtpdev 5.8 Generic_108528-20 sun4u sparc SUNW,Ultra-250
billym.>/bin/sh
billym.>export X=Y
X=Y: is not an identifier
 
Old 11-05-2007, 09:31 AM   #21
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by archtoad6 View Post
Many people think that shell scripts should be written for sh, for portability. OTOH, I learned shell scripting in bash & am not about to give up its richness.
ROTFL, that was my stance as well. Then I stepped into this project and I had to unlearn a lot of things to stay compatible... For testing Bourne compatibility on GNU/Linux I use the Heirloom shell. Strict as hell.
 
Old 11-05-2007, 09:31 AM   #22
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Quote:
billym.>export X=Y
X=Y: is not an identifier
Wow that's ridiculous!!
I haven't got a Slow^H^H^H^HSunOs "easily" to connect to..
Is /bin/sh linked to something?

I remember when I was scripting for different Oses, a bit like doing html for different browsers..

Under cygwin or under busybox's sh or under my linux, I don't have the problem.
 
Old 11-05-2007, 09:32 AM   #23
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Quote:
Originally Posted by unSpawn View Post
Then I stepped into this project and I had to unlearn a lot of things to stay compatible...
That exactly why I forced myself to link sh to dash, to discover all the "bashism" I had created.
Also because it's supposed to be faster.
 
Old 11-05-2007, 10:01 AM   #24
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
it's annoying to try and explain to a supplier to change all their shebangs to ksh
they don't believe it either!

anyway most commercial Unix boxes have ksh (I think all I've used anyway) so I use that.
(I prefer ksh anyway)
 
  


Reply

Tags
scripting, shell, task



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
Shell Scripting greenberet Linux - Software 10 07-06-2006 10:21 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
Shell scripting help rick_james Programming 3 05-20-2005 09:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration