Re: doubt in a script

From: Dan Mercer (dmercer_at_mn.rr.com)
Date: 11/24/05


Date: Thu, 24 Nov 2005 02:13:41 GMT


"Chris F.A. Johnson" <cfajohnson@gmail.com> wrote in message news:71id53-tgu.ln1@rogers.com...
: On 2005-11-23, Eric Haijun Xu wrote:
: > Chris F.A. Johnson wrote:
: >> On 2005-11-23, vishwa wrote:
: >> > Hi ,
: >> >
: >> > I have a doubt in one of the script i use, i want to know what the
: >> > below line does
: >> > typeset TOOLCMD=${0##*/}
: >>
: >> Put this in a script and try it:
: >>
: >> TOOLCMD=${0##*/}
: >> printf "\$0=%s\n" "$0"
: >> printf "TOOLCMD=%s\n" "$TOOLCMD"
: >>
: >>
: >> I wouldn't use the typeset command; read your shell man page to
: >> see what it does.
: >
: > "typeset cmd" is used to define a local variable in a function. why you
: > would not use it?
:
: Becasue it doesn't work in ksh93 unless you use the non-portable
: format for defining functions.

It's perfectly portable to other ksh's. If you are using ksh, your only
portability concern should be to other ksh's, in which the "function"
syntax IS the portable way to define local variables. Portability
is vastly overrated. The Bourne shell is virtually extinct and ash
is used only by extremists.

Besides, it does so much more than creating local variables, it
also determines how they'll be used an expressed (integer, [floating point],
Left justified and truncated, right justified and truncated, upper case, lower
case, [associative array], zero filled...

Dan Mercer

:
: Because "local" makes much more sense for that command.
:
: Because I don't like that use of the word (as a former graphic
: designer and typesetter, it just seems wrong). ;)
:
:
: --
: Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
: Shell Scripting Recipes: | My code in this post, if any,
: A Problem-Solution Approach | is released under the
: 2005, Apress | GNU General Public Licence



Relevant Pages

  • Re: any tips for this script
    ... currently able to execute your script, ... advantage of builtin features of any modern shell that can substitute ... solution is to process your script with the free autoconfig GNU utility, ... it is written with portability in mind ...
    (comp.unix.shell)
  • Re: Secure issues on the usage of exec
    ... :> Do you mean some "Bourne" shells do not inherit IFS? ... :> the shell may actually be a posix shell. ... first you have to get a setuid ksh script running. ... :> As for portability, the subset of portable features in ksh vastly ...
    (comp.unix.shell)
  • Re: Process substitution gives error in script
    ... depends on the shell. ... isn't my script portable ... I'm not sure if I understand the true meaning of portability. ...
    (comp.unix.shell)
  • Re: Unexpected result from grep
    ... :> I have noticed that the Tru64 version of ksh is not a true Korn shell. ... The whole script is excessively complex. ... It actually needs some functionality that isn't available ... Portability using a minimal sh functionality pushes the burden of portability ...
    (comp.unix.shell)
  • Re: Unexpected result from grep
    ... :> I have noticed that the Tru64 version of ksh is not a true Korn shell. ... The whole script is excessively complex. ... It actually needs some functionality that isn't available ... Portability using a minimal sh functionality pushes the burden of portability ...
    (comp.unix.tru64)