🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.debian.user
Article #566

Re: escaping with \ in shells (was: beeps and other sounds)

#566
From: Greg Wooledge
Date: Tue, 17 Nov 2026 03:50
31 lines
2669 bytes
On Tue, Nov 17, 2026 at 03:33:17 +0100, Vincent Lefevre wrote:
> Using single quotes is not possible in these cases.
> 
> $ printf "$?\n"
> 0
> 
> but
> 
> $ printf '$?\n'
> $?

The pedantically correct way to do this would be

    printf '%s\n' "$?"

Or %d if you prefer, since the argument will be numeric with no
leading zeroes.

Yes, it's true that "$?\\n" is safe, because we're guaranteed that $?
will never contain any characters that have special meaning in a
printf format argument.  But that's playing a dangerous game.  In a
future update, someone may see that and decide to add some more
variable expansions to the first argument of printf, and then it
stops being safe.

Besides, if you're going to take shortcuts that are only made possible
by knowledge of content restrictions, just use

    echo "$?"

Why only take *one* shortcut when you can take them all?
Technical Details
Message-ID: <O0imJ-cnE6-3@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod
References: <O04tr-cfJv-27@gated-at.bofh.it> <O04jL-cfFg-3@gated-at.bofh.it> <O05zb-cgt7-1@gated-at.bofh.it> <O06lz-cgMk-3@gated-at.bofh.it> <O0hgZ-cmZn-1@gated-at.bofh.it>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod
From: Greg Wooledge <greg@wooledge.org>
Newsgroups: linux.debian.user
Subject: Re: escaping with \ in shells (was: beeps and other sounds)
Date: Tue, 17 Nov 2026 04:50:01 +0100
Message-ID: <O0imJ-cnE6-3@gated-at.bofh.it>
References: <O04tr-cfJv-27@gated-at.bofh.it> <O04jL-cfFg-3@gated-at.bofh.it> <O05zb-cgt7-1@gated-at.bofh.it> <O06lz-cgMk-3@gated-at.bofh.it> <O0hgZ-cmZn-1@gated-at.bofh.it>
X-Mailbox-Line: From debian-user-request@lists.debian.org  Tue Nov 17 03:47:51 2026
Old-Return-Path: <greg@wooledge.org>
X-Amavis-Spam-Status: No, score=-1.9 tagged_above=-10000 required=5.3
 tests=[BAYES_00=-1.9] autolearn=ham autolearn_force=no
X-Policyd-Weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 CL_IP_EQ_FROM_MX=-3.1; rate: -4.6
Mail-Followup-To: debian-user@lists.debian.org
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
X-Mailing-List: <debian-user@lists.debian.org> archive/latest/832953
List-ID: <debian-user.lists.debian.org>
List-URL: <https://lists.debian.org/debian-user/>
List-Archive: https://lists.debian.org/msgid-search/avvOWSZkC6vHom1N@wooledge.org
Approved: robomod@news.nic.it
Lines: 31
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Date: Mon, 16 Nov 2026 22:47:37 -0500
X-Original-Message-ID: <avvOWSZkC6vHom1N@wooledge.org>
X-Original-References: <avr8-gKZTx-g27RE@wooledge.org>
 <avr6OuVs_c90AmCM@phare.normalesup.org>
 <20261116140728.GA803748@qaa.vinc17.org>
 <avsY_5TT0NYprhPQ@phare.normalesup.org>
 <20261117023317.GB803748@qaa.vinc17.org>