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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
Due to network maintenance being performed by our provider, LQ will be down starting at 05:01 AM UTC. The exact duration of the downtime isn't currently known. We apologize for the inconvenience.
|
 |
|
11-02-2007, 03:58 PM
|
#16
|
|
Member
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195
Rep:
|
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
|
|
|
|
11-03-2007, 12:14 AM
|
#17
|
|
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
|
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.
|
|
|
|
11-05-2007, 03:33 AM
|
#18
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
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
|
|
|
|
11-05-2007, 09:04 AM
|
#19
|
|
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307
Rep:
|
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.
|
|
|
|
11-05-2007, 09:13 AM
|
#20
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
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
|
|
|
|
11-05-2007, 09:31 AM
|
#21
|
|
Moderator
Registered: May 2001
Posts: 24,805
|
Quote:
Originally Posted by archtoad6
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.
|
|
|
|
11-05-2007, 09:31 AM
|
#22
|
|
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307
Rep:
|
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.
|
|
|
|
11-05-2007, 09:32 AM
|
#23
|
|
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307
Rep:
|
Quote:
Originally Posted by unSpawn
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.
|
|
|
|
11-05-2007, 10:01 AM
|
#24
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
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)
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:04 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|