4 ms·
You don't even need the (ls) for file iteration: for i in * echo $i end Fish also has globstar out of the box, so you can do for i in **/* echo
by paradox460 3y ago
You don't even need the (ls) for file iteration:
for i in *
echo $i
end
Fish also has globstar out of the box, so you can do
for i in **/*
echo $i
end
- fuzztester 3y ago[You don't even need the (ls) for file iteration: for i in * echo $i end ] You don't even need the for for that (specific example): echo * at least in sh and bash.
- fuzztester 3y agoAlso, IIRC, and less commonly seen, you can do: for i do # your commands using $i here done which will iterate over all the command line arguments to the script containing that for loop. It is a shortcut for: for i in $* # note: not for i in * # the rest is the same above This is mentioned in either the shell man page or in the Kernighan & Pike book The Unix Programming Environment.
- j16sdiz 3y agoecho * does not have the newline after each file
- fuzztester 3y agoTrue, echo * will print all the filenames on one line, with a space between pairs, but for data processing purposes, the two snippets are equivalent, because as per shell behavior, newline, tab and space are all treated as space, unless quoted. Like the definition of whitespace in the K&R C book. After all, Unix is written in C.
- cdrt 3y agoYou wouldn’t iterate over `echo *` anyway. This works just fine in bash/sh: for file in *; do echo "$file" done