[kwlug-disc] fish vs bash: a progress bar from YSAP and some timing measurements
Ron
ron at bclug.ca
Sat Aug 23 19:56:14 EDT 2025
Ron wrote on 2025-08-23 00:28:
> The fish syntax is *so much better*.
I'm reminded of how nginx came along and really took a lot of install
base from Apache.
Is it because it's faster? Maybe; debatable on equivalent work loads
(from my understanding).
Is it because the configuration syntax is much cleaner, clearer,
legible, and sane?
I think so.
One quirk I've encountered is in passing an array to a function and
accessing it as a variable. This may be due to a failure to understand
something on my part, but I don't think so.
Functions are defined something like this (formatting for personal
preference only):
```
#!/usr/bin/env fish
function myfunc \
--description "This appears in tab-completion hints" \
-a my_arr
echo -e "Inside myfunc \$my_arr has $(count $my_arr) item:\n $my_arr"
echo -e "Inside myfunc \$argv has $(count $argv) items:"
set -l i 1
for arg in $argv
echo " $i/$(count $argv): \$argv[$i]: $argv[$i] (or \$arg: $arg)"
set i (math $i + 1)
end
## printf "myfunc argv passed: %s\n" $argv
end
## In bash, ** requires `shopt -s globstar`
## and `shopt -s nullglob` lest one gets either the string "./**/*.cache"
## if no matches or something else unwanted (I forget)
set files (ls ./**/*.cache)
echo "Found $(count $files) files in a test array"
## Indexing starts at 1 (yay!):
myfunc $files[1..5]
$ ./test2.fish
Found 500 files in a test array
Inside myfunc $my_arr has 1 item:
./baz/delme-100.cache
Inside myfunc $argv has 5 items:
1/5: $argv[1]: ./baz/delme-100.cache (or $arg: ./baz/delme-100.cache)
2/5: $argv[2]: ./baz/delme-101.cache (or $arg: ./baz/delme-101.cache)
3/5: $argv[3]: ./baz/delme-102.cache (or $arg: ./baz/delme-102.cache)
4/5: $argv[4]: ./baz/delme-103.cache (or $arg: ./baz/delme-103.cache)
5/5: $argv[5]: ./baz/delme-104.cache (or $arg: ./baz/delme-104.cache)
❰uid1❙~/utils/ysap-bash/progress-bar❱ ✔ ≻
```
So, passing in an array and capturing the entire array in a local
variable does not (seem to) work.
However, that array is accessible as $argv, so ... that's okay.
I do like that indexing starts at 1 - that's great!
More information about the kwlug-disc
mailing list