Subject: Re: bug#13919: using echo to branch line

From: Pádraig Brady <[email-masked]>
Date: Mon, 11 Mar 2013 01:20:02 +0000

tag 13919 notabug
close 13919
stop

On 03/10/2013 12:44 PM, 王宾 wrote:
> --
> hi,
> As we know:
> [polar@localhost my_shell]$ echo $PATH
> /usr/local/Trolltech/Qt-4.7.4/bin:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/polar/bin:/sbin
> [polar@localhost my_shell]$
> when i use
> [polar@localhost my_shell]$ echo  ${PATH//:/'\n'}   -e
> to branch line and hope the result may be like this
> [polar@localhost my_shell]$ echo $PATH | sed 's/:/\n/g'
> /usr/local/Trolltech/Qt-4.7.4/bin
> /usr/lib/qt-3.3/bin
> /usr/kerberos/bin
> /usr/local/bin
> /usr/bin
> /bin
> /usr/X11R6/bin
> /home/polar/bin
> /sbin
> [polar@localhost my_shell]$
> but i can't get the result according---echo  ${PATH//:/'\n'}   -e, and i have searched the Internet but no answer, so i send this e-mail to you for help,  thank you for sparing your time and  thank you for your answer!

You need the -e first, for it to be interpreted as an option.
Be wary though, as echo has bad portability between various systems.

$ echo -e "${PATH//:/\n}"
/usr/bin
/bin

$ printf '%s\n' "$PATH" | tr ':' '\n'
/usr/bin
/bin

thanks,
Pádraig.