Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: optimal expansions?
- X-seq: zsh-users 29854
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- Cc: Ray Andrews <rayandrews@xxxxxxxxxxx>, zsh-users@xxxxxxx
- Subject: Re: optimal expansions?
- Date: Sun, 21 Apr 2024 21:13:51 +0100
- Archived-at: <https://zsh.org/users/29854>
- In-reply-to: <CAN=4vMppE4cXuvK=rkxGO7KeLRY1nt0LV9pm40mbTaG9MQoCMw@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>, Ray Andrews <rayandrews@xxxxxxxxxxx>, zsh-users@xxxxxxx
- References: <53fab6be-26d7-4de5-844f-ffc295d9a494@eastlink.ca> <CAN=4vMqfcxt-C-g=4Sk13Qu28LFK46QCfXajhHfFMzLCcsXysg@mail.gmail.com> <3d15311d-b5fa-4a55-a17e-e61fcdded7d0@eastlink.ca> <CAN=4vMqoWSkGbnDuBqBBfCW602FeROjHV0npQVoTw+phRvZDAg@mail.gmail.com> <9fe68299-c89f-46a1-b10f-eefadd03a262@eastlink.ca> <CAN=4vMrmUdgGuhDZjrrhCvQZaiSyCMPm0yAZMM0DYUGf6efDjg@mail.gmail.com> <20240421161440.jicmznwxqb6pz2fg@chazelas.org> <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author