JP Vossen on 22 Apr 2010 00:02:53 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Shell scripting?


First off, I have to say, wow.  I really didn't expect so much feedback 
and enthusiasm so quickly.  I'll put something together, but probably 
not for a few months.  I'm already going to be doing "Cool_Ubuntu_Apps" 
soon...

Meanwhile, to address some specific points...


> Date: Wed, 21 Apr 2010 09:28:27 -0400
> From: Randall A Sindlinger <rsindlin+plug@seas.upenn.edu>
> 
> I realize this is the Philly *Linux* Users Group, but it still kind of
> bothers me when I see #!/bin/sh

You know what bugs me at the *Linux* user group?  All the Macs.<ducks>


> Granted, on linux #!/bin/sh is symlinked to bash, but if you try to 
> use the script on some unix variant, you're in for a very big
> surprise.  /bin/sh and /bin/bash are *not* the same there.
> So, it's just me, but I always prefer explicitly saying #!/bin/bash
> on scripts I write.

As Paul and possibly other folks pointed out, /bin/sh is *not* always a 
symlink to bash, even  on Linux.  (See 
http://princessleia.com/plug/2008-JP_bash_vs_dash.pdf).  But I haven't 
noticed anyone else pointing out that /bin/bash doesn't always exist. 
AFAIK it does on Linux, but it may or may not be installed and if 
installed may or may not be in /bin/ on other platforms.

The following is the POSIX portable way to invoke bash (if installed):
	#!/usr/bin/env bash

Having said that, I mostly write for Linux, and mostly specify bash if I 
use any "bash-isms" which I usually do.  See the slides above for details.



> Date: Wed, 21 Apr 2010 08:14:56 -0400
> From: "Kyle R. Burton" <kyle.burton@gmail.com>
> 
> I think that doing a 101 presentation is a great idea.  Other topics
> that would be interesting to me are:
> 
> * a 101 workshop

Interesting idea.  Might be tricky to coordinate.  Or I might be 
over-thinking it too.


> * Shell / environment customization tips, tricks and examples
> 
> This could be a presentation or a workshop or both, it is becoming
> more common (seems to me) for Linux users to put their entire profile
> or shell customizations up on a code hosting site (eg:
> http://github.com/trotter/profile).  I've stated doing this and I find
> it very valuable because I work on multiple machines and have to set
> new machines up every once in a while.  Sharing my configuration is
> easier because I can just pull a recent copy of the archive, which
> also makes it easier to set new machines up.  This could cover some
> favorite aliases, bash functions, environmental setup, favorite
> default options, a 'best of' or most useful dot or rc files to know.
 >
 > * Demystifying the shell prompt (PS1, ...) and making it work for you

I wrote a whole chapter on that in the _bash Cookbook_, and I've listed 
some resources on similar things at 
http://www.bashcookbook.com/bashinfo/#RepoRefs.  I'd certainly be 
interested in hearing from other folks about this too.


> Creating your own simple completions using the bash 'complete' function:

See also:
http://www.bashcookbook.com/bashinfo/#examples/complete
http://www.caliban.org/bash/

Note Ian Macdonald's bash completion is in the Debian/Ubuntu repos, but 
not always installed by default or enabled, depending on the distro and 
user.


> My intent isn't necessarily to volunteer JP to talk on these subjects,
> but these are non-obvious things I'd have liked to have been exposed
> to earlier in my Linux usage.  I would be happy to either collaborate
> with JP or talk about these myself...

Yeah, everyone will get sick(er) of me...  :-)



 > Date: Wed, 21 Apr 2010 09:49:12 -0400
 > From: "Paul L. Snyder" <plsnyder@drexel.edu>
 >
[...]
 > Portable shell scripting consists mostly of corner cases, and if you
 > think your script is portable, it still probably has nasty surprises
 > lurking.

I strongly agree.  And many of those corned cases are caused by 
differences in tools, esp. 'ps' and the GNU tools.  I love GNU tools, 
but they are too darn friendly and useful!  You get spoiled.  :-)
(See my printf thread)


 > If you're using bash-specific features, you should
 > definitely specify bash in the shebang line.

I agree.


 > I use zsh for personal-use shell scripts, as the limitations of the
 > classic Bourne shell are unpleasantly confining.

Ooooo, them's fightin' words!  :-)


Later,
JP
----------------------------|:::======|-------------------------------
JP Vossen, CISSP            |:::======|      http://bashcookbook.com/
My Account, My Opinions     |=========|      http://www.jpsdomain.org/
----------------------------|=========|-------------------------------
"Microsoft Tax" = the additional hardware & yearly fees for the add-on
software required to protect Windows from its own poorly designed and
implemented self, while the overhead incidentally flattens Moore's Law.
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug