[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:49:14 +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"
>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.
- \n displayed instead of newline, lisa-asket, 2021/06/29
- Re: \n displayed instead of newline, Jesse Hathaway, 2021/06/29
- Re: \n displayed instead of newline, Greg Wooledge, 2021/06/29
- \n displayed instead of newline,
lisa-asket <=
- \n displayed instead of newline, lisa-asket, 2021/06/30
- Re: \n displayed instead of newline, Greg Wooledge, 2021/06/30
- \n displayed instead of newline, lisa-asket, 2021/06/30
- Re: \n displayed instead of newline, Greg Wooledge, 2021/06/30
- \n displayed instead of newline, lisa-asket, 2021/06/30
- Re: \n displayed instead of newline, Greg Wooledge, 2021/06/30
- Re: \n displayed instead of newline, Leonid Isaev (ifax), 2021/06/30
- \n displayed instead of newline, lisa-asket, 2021/06/30