Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Aug 2000 08:59:39 +0200
From:      Martin Cracauer <cracauer@cons.org>
To:        Jappe Reuling <jappe@lowlife.org>
Cc:        freebsd-bugs@FreeBSD.ORG
Subject:   Re: I think I found a bug in /bin/sh
Message-ID:  <20000817085938.A20046@cons.org>
In-Reply-To: <Pine.BSF.4.21.0008161520460.4876-100000@bsd.t-l.org>; from jappe@lowlife.org on Wed, Aug 16, 2000 at 03:33:55PM %2B0200
References:  <Pine.BSF.4.21.0008161520460.4876-100000@bsd.t-l.org>

next in thread | previous in thread | raw e-mail | index | archive | help
In <Pine.BSF.4.21.0008161520460.4876-100000@bsd.t-l.org>, Jappe Reuling wrote: 
> 
> Hi,
> 
> While writing a shell script I came acros something strange. I used an
> alias for 'echo' and it looks like the alias is ignored in a case
> statement. The code below produces the following on the screen:
> 
> ----
> H
> e
> l
> l
> o
> Hello
> ----
> 
> ----
> #!/bin/sh
> 
> alias echo="/bin/echo -n"
> 
> hello() {
> 
> local foo
> 
>   foo=1
> 
>   case $foo in
>   1)
>     echo "H"
>     echo "e"
>     echo "l"
>     echo "l"
>     echo "o"
>   ;;
>   esac
> 
>   echo "H"
>   echo "e"
>   echo "l"
>   echo "l"
>   echo "o"
> 
> }
>  
> hello

aliases are meant for interactive use.  In shellscripts, you should
use a shell function instead.

Replacing your alias with

echo ()
{
        /bin/echo -n "$@"
}

works fine for sh, bash, pdksh and zsh, whereas the alias solution
differs greatly (bash documentation explicitly says that aliases are
not expanded in scripts).

Also, I would not alias anything that is subject to the
buildin-vs-extern command chaos anyway.

Of course, it is technically a bug that our sh considers the alias one
time and not the other.  I'll check POSIX when I'm at home and see if
there are any rules concerning aliases in non-interactive.  I doubt
it, though.

If you want to make sure this gets fixed, please submit a formal bug
report using send-pr or http://www.FreeBSD.org/send-pr.html.

Thanks!
	Martin
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer/
BSD User Group Hamburg, Germany     http://www.bsdhh.org/


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000817085938.A20046>