From: Stephane Chazelas <stephane@chazelas.org>
To: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Cc: Ray Andrews <rayandrews@eastlink.ca>, zsh-users@zsh.org
Subject: Re: optimal expansions?
Date: Sun, 21 Apr 2024 21:13:51 +0100 [thread overview]
Message-ID: <20240421201351.n5cku2gqf246joaf@chazelas.org> (raw)
In-Reply-To: <CAN=4vMppE4cXuvK=rkxGO7KeLRY1nt0LV9pm40mbTaG9MQoCMw@mail.gmail.com>
2024-04-21 19:39:20 +0200, Roman Perepelitsa:
[...]
> I'm curious. Which of these would you use?
>
> print rebooting
> print -r -- rebooting
Probably print -u2 rebooting, though in scripts, I usually
define functions for reporting like:
info warn err() print -ru2 -C1 -- "$@"
die() { err "$@"; exit 1; }
info rebooting
In any case, for fixed strings, whether to use -- (or - which
also works for print) or not is not relevant as long as the
string doesn't start with "-" (or "+" for some commands). Same
for -r as longer as arguments don't contain backslashes.
The -- is needed when arguments are not known at code writing
time (or are known to be a problem).
> Or these:
>
> ls ~
> ls -- ~
>
> I prefer the first form in both of these examples, whether in scripts
> or interactively. It's less code, so less time to read and understand.
[...]
Strictly speaking, it should be ls -- ~ as ~ expands to $HOME
which we can't guarantee won't start with - (though $HOME
starting with - would only happen in pathological cases).
--
Stephane
next prev parent reply other threads:[~2024-04-21 20:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-19 19:22 Ray Andrews
2024-04-19 20:40 ` Lawrence Velázquez
2024-04-19 23:25 ` Ray Andrews
2024-04-20 7:42 ` Roman Perepelitsa
2024-04-20 14:23 ` Ray Andrews
2024-04-20 22:54 ` Lawrence Velázquez
2024-04-20 23:59 ` Ray Andrews
2024-04-21 12:23 ` Roman Perepelitsa
2024-04-21 14:09 ` Ray Andrews
2024-04-21 14:19 ` Roman Perepelitsa
2024-04-21 16:14 ` Stephane Chazelas
2024-04-21 17:39 ` Roman Perepelitsa
2024-04-21 20:13 ` Stephane Chazelas [this message]
2024-04-21 20:46 ` Lawrence Velázquez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240421201351.n5cku2gqf246joaf@chazelas.org \
--to=stephane@chazelas.org \
--cc=rayandrews@eastlink.ca \
--cc=roman.perepelitsa@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).