qi(1)
: Builtins
#154
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I don't like the shell built-in
shift
.It seems to mainly exist as an equivalent to the C idiom
++argv; --argc;
which is (given the benefit of >30 years of hindsight since C89) a complicating and not very readable way to save memory processing arguments.Its definition in POSIX makes it unintuitive for shell scripters. Emma should elaborate here when fae has time, fae has more experience with this.
It necessitates storing
"$0"
as a new shell variable to be able to continue using it, which shell authors writing diagnostics messages and following good practice always want to do.It's inflexible; it can only be used for the one task of shifting through arguments.
shift
is the only real way to iterate over arguments ($1
,$2
,$3
...) in shell. Particularly with the following idiom:What if variables could hold the names of other variables? Not like pointers in C but simply:
This could be used for better argument usage:
for
in this example is a shell built-in that, for each line in standard input, sets the given variable (in this casei
) to that line's content before running the commands in the curly braces. seq(1) in this usage prints a new-line delimited list of integers in the sequence described in its arguments.out
is an analogue to echo(1) as currently being described in #27.This might be a terrible idea that can be used to write terrible scripts. Also, there is no real concept of betta(1) yet, so I'm basing my examples off sh(1p).
Originally posted by @trinity in #8 (comment)
shift(1) does not modify the value of
$0
, actually. From shift(1p):Originally posted by @emma in #8 (comment)
Originally posted by @emma in #8 (comment)
The only built-in commands I see as absolutely necessary are
let
(or a way to change the shell environment; see #152) andcd
orchdir
.The argument that built-ins drastically speed up shell scripts by avoiding the overhead of spawning a new process is fair but doesn't sway me as built-ins are often a great source of confusion (
echo -n foo
and$(command -v foo)
disagreeing is always weird).