Timeline for Simple loop of files - 'file name too long'
Current License: CC BY-SA 4.0
18 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 30, 2022 at 12:30 | comment | added | benwiggy | I guess I'm looking for the shell equivalent of passing files to a function. | |
| Aug 30, 2022 at 12:22 | history | edited | ilkkachu | CC BY-SA 4.0 |
added 55 characters in body
|
| Aug 30, 2022 at 12:18 | comment | added | Stéphane Chazelas |
find "/Users/Ben/Pictures/Stock Illustrations" -type f -print -exec pstopdf {} \; could end up calling pstopdf on files created by a previous invocation of pstopdf.
|
|
| Aug 30, 2022 at 12:17 | comment | added | Stéphane Chazelas | OP is using zsh, not bash nor sh. | |
| Aug 30, 2022 at 12:14 | comment | added | ilkkachu |
@benwiggy, you could just add multiple -exec options, like find ... -exec somecmd {} \; -exec othercmd {} \; and it should run them each in order. That's more like running somecmd "$f" && othercmd "$f" in the shell, in that if any of the commands fails, it would stop there and not run the next one. (That's what I think it should do, since the -exec stanzas also act as conditions.) Or you could run all that via a shell find ... -exec sh -c 'somecmd "$1"; othercmd "$1"' sh {} \; or find ... -exec sh -c 'for f do somecmd "$f" && othercmd "$f"' sh {} +
|
|
| Aug 30, 2022 at 11:45 | comment | added | benwiggy | Is it easy to add multiple commands to an exec option? | |
| Aug 30, 2022 at 11:38 | vote | accept | benwiggy | ||
| Aug 30, 2022 at 11:35 | comment | added | ilkkachu |
@benwiggy, ah, note that $'...' isn't POSIX, it works in Bash/ksh/zsh and Busybox, but not all pure POSIX shells. You could use IFS='<newline>' with a literal newline there in a POSIX shell, but it's somewhat hard to read.
|
|
| Aug 30, 2022 at 11:33 | history | edited | ilkkachu | CC BY-SA 4.0 |
added 26 characters in body
|
| Aug 30, 2022 at 11:27 | comment | added | benwiggy | Yes, the wildcard filepath works now - though I'm sure I ruled that out previously for some other error! | |
| Aug 30, 2022 at 11:25 | comment | added | benwiggy |
I'm still getting the File name too long error with your IFS=$'\n' method.
|
|
| Aug 30, 2022 at 11:18 | comment | added | ilkkachu |
@benwiggy, there's also for f in /some/path/**/*; do ... for a recursive glob, if you don't need the more specific filters find has.
|
|
| Aug 30, 2022 at 11:17 | history | edited | ilkkachu | CC BY-SA 4.0 |
added 178 characters in body
|
| Aug 30, 2022 at 11:15 | comment | added | terdon♦ |
@benwiggy that is your call, of course, but note that the for loop approach above will be slower and less efficient than find and also cannot deal with file names with newline characters. The pure find approach is far better: it is more concise, more efficient, and more robust to strange file names.
|
|
| Aug 30, 2022 at 11:15 | history | edited | ilkkachu | CC BY-SA 4.0 |
added 8 characters in body
|
| Aug 30, 2022 at 11:14 | comment | added | benwiggy | Thank you. I prefer the more structured multi-line approach with a for loop. | |
| Aug 30, 2022 at 11:12 | comment | added | ilkkachu |
Whoops, Jeff's answer in the other one did also have the find -exec.
|
|
| Aug 30, 2022 at 11:10 | history | answered | ilkkachu | CC BY-SA 4.0 |