Re: .bashrc aliases



2006-02-22, 13:13(-08), Xicheng:
[...]
alias next='the command above'

with the proper punctuation. Thanks.

In bash, you can use 'function' instead of 'alias' which pretty much
does the same thing, so you may do:

function next() { osascript -e 'tell app "iTunes" to next track'; }
[...]

Where does that new trend for defining a function come from?
Does some manual or book advertise it?

That's the awk syntax, that's neither the ksh nor the Bourne
syntax. And it's not POSIX conformant. It just happens to work
for bash and zsh, because those shells just happen to ignore the
"function" there. They accept it because the ksh way includes
it.

ksh was the first (before the Bourne shell) to introduce
functions. It chose to write it as:

function next {
...
}


Then the Bourne shell chose to write it as:

next() {
...
}

Later on, ksh also accepted that one to be compatible with the
Bourne shell again (note that in ksh, those two define two
different kinds of functions, for instance the signal handling
is different for a function defined in one way than the same
function defined the other way).

The POSIX and UNIX specification only recognise the Bourne way.

Some Bourne-like shells, like bash or zsh implement the Bourne
way. They recognise the ksh way, but don't make any difference
contrary to ksh.

--
Stéphane
.



Relevant Pages

  • Re: Announcement: bashcritic
    ... The canonical syntax is foo() ... "Bourne Shell": http://en.wikipedia.org/wiki/Bourne_shell ... Although ksh had a version 1982 or 1984, ...
    (comp.unix.shell)
  • Re: OT: The Straight Dope
    ... > know about bash, ksh, or sh. ... I believe the Bourne shell is where the backticks as "execute string ... C-shell programming generally seems to be deprecated in most ...
    (comp.lang.python)
  • Re: Announcement: bashcritic
    ... is POSIX," the braceless function body code would have ... added support for the Bourne syntax for Bourne compatibility, ... No. ksh has always been built upon the Bourne shell codebase, ...
    (comp.unix.shell)
  • Re: csh question: foreach
    ... /bin/sh as shorthand for bourne shell. ... > bash if it's what you meant. ... ksh and zsh both can deal gracefully with it--why not bash? ...
    (comp.unix.solaris)
  • Re: csh question: foreach
    ... /bin/sh as shorthand for bourne shell. ... > bash if it's what you meant. ... ksh and zsh both can deal gracefully with it--why not bash? ...
    (comp.unix.shell)