[Ilugc] One Day One Command

  • From: suraj@xxxxxxxxxxx (Suraj)
  • Date: Fri Jan 7 07:52:01 2005

T.R.Shashwath wrote: 
,----
| Try writing  a whole script  within an alias... Somewhat  useless, but
| could be useful also.
`----

(please dont 'top-post').

Thats not  my point.  alias is a  literal expansion. For  example, you
cannot make your 'function' take arguments. For example if you want to
take a file as an argument to your alias and then cat that file and do
something...

cat <file> | ssh myhost "perl -e 'some code'"

this isn't  possible with a shell  alias. You *will* have  to define a
function.

Of course, you can do this:

alias x='function f { cat $1 |  ssh myhost "perl -e 'some code'"; };f'

But  whas the point?  you could  have pre-defined  'f' anyway  in your
bashrc.

cheers,

  -Suraj

On Thursday 06 Jan 2005 7:09 pm, Suraj wrote:

T.R.Shashwath wrote:
,----

| ...Including the ability to use a whole function definition in it...
|
| alias something="foo() { echo $bar }

`----

you can 'define'  a function, yes.  But whats your  point?  alias is a
literal expansion.  its very much like a pre-processor operation.

alias foo="function bar() { echo hello world; }"

will only  'define' the function 'bar'  when you type  'foo'. Its just
that instead of  having to type of the entire  function, you typed out
'foo'. and the above example is slightly misleading, in a way, in that
if people try to type 'foo test message', they would get syntax errors
because it does literal expansion.

some examples:

$ alias intemp="cd /tmp; "
$ intemp ls
<output of ls>
$ pwd
/tmp

$ alias obfuscated="function myfunc() {"
$ obfuscated echo hello world; }; myfunc
hello world
$

cheers,

  -Suraj

-- 
To know a thing well, know its limits. 
Only when pushed beyond its tolerances will true nature be seen.
--The Amtal Rule - Dune
---end quoted text---

-- 
,-----------------[http://www.symonds.net/~suraj/]---o
| Mysore T. Chowdiah is also a composer with the mudra trimakoota (after his
| birth place tirumakoodlu or T.narasipura)
`------------------------------[suraj@xxxxxxxxxxx]---o

Other related posts: