PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > internal alias
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

internal alias

Réponse
 
LinkBack Outils de la discussion
Vieux 08/01/2008, 00h43   #1
reader@newsguy.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut internal alias

I'm accustomed to using ksh93 and have a number of scripts written for
that interpreter. I have to convert them to bash. And I find mostly
thery are compatable but for the echo/print difference.

I've grown to prefer `print' so that is scattered all over these
scripts.

Looking for a lazy way out:

I didn't notice anything in the manual to me see how or if it can
be done.

I wondered if there is some mechanism in bash where inside a script I
could alias `print' to `echo' instead of having to actually change
them all.

It would be much simpler to just put something at the top of each
script that makes bash see `echo' where it says `print' and see
if the script will run ok otherwise.
  Réponse avec citation
Vieux 08/01/2008, 04h16   #2
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: internal alias

On Mon, 07 Jan 2008 18:43:13 -0600, reader wrote:

> I'm accustomed to using ksh93 and have a number of scripts written for
> that interpreter. I have to convert them to bash. And I find mostly
> thery are compatable but for the echo/print difference.
>
> I've grown to prefer `print' so that is scattered all over these
> scripts.
>
> Looking for a lazy way out:
>
> I didn't notice anything in the manual to me see how or if it can
> be done.
>
> I wondered if there is some mechanism in bash where inside a script I
> could alias `print' to `echo' instead of having to actually change them
> all.
>
> It would be much simpler to just put something at the top of each script
> that makes bash see `echo' where it says `print' and see if the script
> will run ok otherwise.


Add a function called "print", e.g.

print(){ echo "$@" ;}

  Réponse avec citation
Vieux 09/01/2008, 21h25   #3
bsh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: internal alias

On Jan 7, 4:43pm, rea...@newsguy.com wrote:
> I'm accustomed to using ksh93 and have a number of scripts written for
> that interpreter. I have to convert them to bash. And I find mostly
> thery are compatable but for the echo/print difference.


Too bad. Despite some opinions to the contrary, ksh(1) version
1993 is in design and execution a superior shell to bash(1).

> I've grown to prefer `print' so that is scattered all over these
> scripts.


Keep in mind that that options acceptable to "echo" (builtin
_and_ external versions!) are a small subset of the capabilities
of ksh(1) print and printf.

> Looking for a lazy way out:


The previous reply is sufficient, but you still might gain some
advantage from automated conversion utitilies, if your host OS
is commensurate. See my past post at:

http://groups.google.com/group/comp....ed6773be861c72

=Brian
  Réponse avec citation
Vieux 10/01/2008, 05h48   #4
reader@newsguy.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: internal alias

Icarus Sparry <usenet@icarus.freeuk.com> writes:

>> It would be much simpler to just put something at the top of each script
>> that makes bash see `echo' where it says `print' and see if the script
>> will run ok otherwise.

>
> Add a function called "print", e.g.
>
> print(){ echo "$@" ;}


Now that is pretty slick... I wouldn't have thought of it in a dozen
years. I'd like to think I'd have thought after while but naa.. I
wouldn't have.

In this case I guess it is fortunate that my scripts are primitive. I
think I can just change `echo' to `echo -e' for the occasions where my
print calls involve newlines all of them will just work.

You saved me from breaking a dedication to laziness since I retired a
few years ago.
  Réponse avec citation
Vieux 10/01/2008, 06h00   #5
reader@newsguy.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: internal alias

bsh <brian_hiles@rocketmail.com> writes:

>> I'm accustomed to using ksh93 and have a number of scripts written for
>> that interpreter. I have to convert them to bash. And I find mostly
>> thery are compatable but for the echo/print difference.

>
> Too bad. Despite some opinions to the contrary, ksh(1) version
> 1993 is in design and execution a superior shell to bash(1).
>


It will probably start a religious war but I'm kind of curious what
you have in mind. I suspect it will be pretty much outside of my
usage though since my skill are pretty low level.

I liked ksh93 for the regex matching.. like having awk in your shell
script without calling it. I did not realize that bash now possesses
that skill too ... the =~ operator.

Not sure when that happened but I think its kind of new. I have'nt
really used bash for a good while, except for actual shell. All shell
scripting was in ksh.

I'm starting to think I might be smarter to just go with bash. At my
usage level its very close.
  Réponse avec citation
Vieux 10/01/2008, 07h43   #6
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: internal alias

On Thu, 10 Jan 2008 00:00:47 -0600, reader wrote:

> bsh <brian_hiles@rocketmail.com> writes:
>
>>> I'm accustomed to using ksh93 and have a number of scripts written for
>>> that interpreter. Â I have to convert them to bash. ÂAnd I find mostly
>>> thery are compatable but for the echo/print difference.

>>
>> Too bad. Despite some opinions to the contrary, ksh(1) version 1993 is
>> in design and execution a superior shell to bash(1).
>>
>>

> It will probably start a religious war but I'm kind of curious what you
> have in mind. I suspect it will be pretty much outside of my usage
> though since my skill are pretty low level.
>
> I liked ksh93 for the regex matching.. like having awk in your shell
> script without calling it. I did not realize that bash now possesses
> that skill too ... the =~ operator.


There are things that awk & ksh (& perl & tcl & python & lua & ...) have
but bash does not such as associative arrays. For trivial sizes you can
simulate them with a linear search and a pair of arrays, but this soon
gets slow. So then you start programing some kind of balanced heap. Soon
your quick little script starts to run to thousands of lines and people
start asking why you didn't program it in awk/perl/python/whatever.

Then there are floating point numbers.

Then you can load commands into ksh93 to avoid lots of the overhead. True
you can add extensions to bash, but then you may hit licensing issues (no
one seems very sure if you dynamicaly load code into bash if you have to
make it available under the GPL - the concensus at work is "yes")

Then there is the better option parser, complete with the ability to
generate man pages.
> Not sure when that happened but I think its kind of new. I have'nt
> really used bash for a good while, except for actual shell. All shell
> scripting was in ksh.
>
> I'm starting to think I might be smarter to just go with bash. At my
> usage level its very close.


If you have a choice, I would stick with ksh93.
  Réponse avec citation
Vieux 10/01/2008, 16h33   #7
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: internal alias

On 2008-01-08, Icarus Sparry wrote:
>
> print(){ echo "$@" ;}


Better would be:

print()
{
printf "%b\n" "$*"
}

Even better would be to add handling for print's options.

Or, if you are using bash, there is a dynamically loadable version
of print that comes with the source code.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 10/01/2008, 17h16   #8
reader@newsguy.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: internal alias

Icarus Sparry <usenet@icarus.freeuk.com> writes:

>> It will probably start a religious war but I'm kind of curious what you
>> have in mind. I suspect it will be pretty much outside of my usage
>> though since my skill are pretty low level.
>>
>> I liked ksh93 for the regex matching.. like having awk in your shell
>> script without calling it. I did not realize that bash now possesses
>> that skill too ... the =~ operator.

>
> There are things that awk & ksh (& perl & tcl & python & lua & ...) have
> but bash does not such as associative arrays.


That sounds useful. Can you give an example of associative array
usage in ksh?

I forgot the main reason I liked ksh over bash and that is how easy it is
to generate a regular array with `set -A'.

Someone may know how to do that as easily in bash but it has escaped
me.

[...]

>> I'm starting to think I might be smarter to just go with bash. At my
>> usage level its very close.

>
> If you have a choice, I would stick with ksh93.


Just thinking out loud here:
The things you've mentioned are things I've never touched in ksh and
as you point out, at the point where things like that become needed,
its time for perl or python etc.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h30.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,24152 seconds with 16 queries