Interesting #ShellScripting quandary:
I'm uncertain how shells delimit filename variables internally.
I have a shell (bash) function that loops through a set of PDF files, opening them in zathura in a "suckless" tabbed window (so that the PDFs always open within the same window, so I can just hit q
to zip through them one-at-a-time.
Here is my variable declaration:
local files=${*-*.[pP][dD][fF]}
But for simplicity, you could just imagine it to be:
files=*
Then I'm doing a
for f in $files; do
I'm wanting to print a status line for each item viewed, so I have an idea how many more there are to go, so I'm using this:
echo "[[$f]] ($count/$tot)"
And of course, there's a ((count++))
at the beginning of the loop.
But how to get the total ($tot
)??
echo $files |wc -l
will always result in 1
, as does echo "$files" |wc -l
What I ended up doing was just creating a
for f in $files; do ((tot++)); done
One-liner loop before the actual loop, just to get a total.
Is there a better way?
Am I missing something really obvious?