[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: BASH Command substitution
From: |
Chris F.A. Johnson |
Subject: |
Re: BASH Command substitution |
Date: |
Thu, 17 Dec 2009 09:37:11 -0500 (EST) |
User-agent: |
Alpine 2.00 (LMD 1167 2008-08-23) |
On Thu, 17 Dec 2009, Zoltan Mate wrote:
> Dear Chet Ramey,
>
> I have a conversation on an other bug forum, then have been directed
> to here, I cannot find any documentation, why
>
> $ echo $(echo "'alfa beta'")
> gives 'alfa beta' whith reduced space, instead of the result of the
> following more logical ways:
>
> $ echo $(echo "'alfa beta'")
> the second term suggests one parameter being substituted as
> "<the output of the command>"
>
> On the other hand, having made the substitution, one should get the
> $ echo 'alfa beta'
> text to be interpreted.
>
>
> So why the '-s are quoted and the spaces are not?
> This strange behaviour should be mentioned in the bash manual.
The output of the command substitution is two arguments. It you
want it intepreted as one, quote it:
echo "$(echo "'alfa beta'")"
> ----------------------------------------- The former conversation:
> --------------------------------------------
> bash command substitution reduce double spaces in strings:
>
> $ echo $(echo "'alfa beta'")
> 'alfa beta'
>
>
> Reproducible: Always
>
> Steps to Reproduce:
>
>
> ------- Comment #1 From SpanKY 2009-12-16 19:32:24 0000 [reply] -------
>
> the second isnt actually quoted which means you ran:
> argv[] = {
> "echo"
> "'alfa"
> "beta'"
> }
>
>
> ------- Comment #2 From ZoliM 2009-12-17 09:41:08 0000 [reply] -------
>
> Where is emphasized the text interpreatation process in the manual?
>
> In
> $ echo $(echo "'alfa beta'")
> the second term suggests one parameter being substituted as
> "<the output of the command>"
>
> On the other hand, having made the substitution, one should get the
> $ echo 'alfa beta'
> text to be interpreted.
>
> So I motion to mark in the documentation at the Command substitution chapter
> the proper interpretation logic.
>
>
> ------- Comment #3 From SpanKY 2009-12-17 10:32:32 0000 [reply] -------
>
> those two examples are not equivalent. your first snippet boils down to:
> echo \'alfa beta\'
>
> this bugzilla isnt a forum for teaching people how to script bash. if you
> want
> further help, please ask on the bash mailing list, or the gentoo forums, or
> some other suitable location.
--
Chris F.A. Johnson, webmaster <http://woodbine-gerrard.com>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)