Re: [expert] Bug in Bash ?

2002-12-12 Thread kwan
On Thu, 12 Dec 2002, Bill Shirley wrote:

> I'm trying to make an bash alias do what I want an things are not
> working as
> expected.
> 
> [root@server1 samba]# alias ta='echo /var/log/samba/log.${1:-smbd}'
> [root@server1 samba]# ta
> /var/log/samba/log.smbd
> [root@server1 samba]# ta server2
> /var/log/samba/log.smbd server2
> 
> I would think the second invocation of ta to produce:
> /var/log/samba/log.server2
> 
> but it doesn't.  Is there something I don't understand?
> 
I think the error you're getting is from when/where the positional
parameters are expanded:
If you do
alias foo='echo x $1 y $2 z $3'
foo a b c
You'll get
xyz abc

This is because it doesn't know about the positionals and is just doing:
echo x $1 y$2 z $3 abc

To get around this you can use a sourced function:

function foo{
  echo x $1 y $2 z $3
}

You can put this in your .bash_profile or .bashrc to be available
anytime.


Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com



Re: [expert] Bug in Bash ?

2002-12-12 Thread Jack Coates
On Thu, 2002-12-12 at 06:26, Bill Shirley wrote:
> I'm trying to make an bash alias do what I want an things are not
> working as
> expected.
> 
> [root@server1 samba]# alias ta='echo /var/log/samba/log.${1:-smbd}'
> [root@server1 samba]# ta
> /var/log/samba/log.smbd
> [root@server1 samba]# ta server2
> /var/log/samba/log.smbd server2
> 
> I would think the second invocation of ta to produce:
> /var/log/samba/log.server2
> 
> but it doesn't.  Is there something I don't understand?

Not sure what you want, but I can see that 
echo /var/log/samba/log.${1:-smbd}
is going to produce
/var/log/samba/log.smbd
no matter what is in $1. If you want to process $1, you have to call it
in the alias:
alias ta=/var/log/samba/log.$1
That still inserts a space though, and I'm not sure how to remove it:
[jack@chupacabra jack]$ ta beavis
/var/log/samba/log. beavis

-- 
Jack Coates
Monkeynoodle: A Scientific Venture...



Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com