[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: \n displayed instead of newline
From: |
Greg Wooledge |
Subject: |
Re: \n displayed instead of newline |
Date: |
Tue, 29 Jun 2021 14:26:52 -0400 |
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.
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.
- \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 <=
- \n displayed instead of newline, lisa-asket, 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
- \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