help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

\n displayed instead of newline


From: lisa-asket
Subject: \n displayed instead of newline
Date: Wed, 30 Jun 2021 07:58:34 +0200 (CEST)

>From: Greg Wooledge <greg@wooledge.org>
>To: help-bash@gnu.org
>Subject: Re: \n displayed instead of newline
>Date: 29/06/2021 20:26:52 Europe/Paris

>On Tue, Jun 29, 2021 at 07:50:05PM +0200, lisa-asket@perso.be wrote:
>> Why does the first `\n` display as a string rather than a newline in the 
>> following printf?   
>> 
>> 
>> 
>> printf "Usage: $ua\n       $ub\n"

>It doesn't.

>However, you've got a problem (bug) here: you're passing arbitrary
>expanded variables to printf as part of its format argument. If one or
>both of those variables contain syntax that printf uses for formatting,
>you'll get undesired results.

Understood.  Thanks



>The correct way to write this would be:

>printf 'Usage: %s\n       %s\n' "$ua" "$ub"



This is what I have



    ua="grep -ir --exclude=\\*.el --include=\\*.{org,texi}  \\"
    ub="  -C 8 \"hilbert\" /marshall/"
    printf "Usage: %s\n %s\n" $ua $ub





>It's possible that whatever symptom you're seeing is the result of
>there being backslashes or other special characters in the ua variable.
>Therefore, for debugging purposes, your first instinct should be to
>dump the contents of the ua and ub variables at the time this printf
>command runs. You can do this with "set -x", or by explicitly running
>"declare -p ua ub", or several other possible ways.

Yes, I got backslashes in the `ua` and `ub` variables.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]