last day (15 days later) » 

19:55
6
A: How do I use zsh to pipe results from one command to another (while in a loop)?

nohillsideDo not parse/interpret the output of ls, too many things can go wrong. A simple way to accomplish your goal would be for f in *.vital; do echo -n "$f: " jq '.author' "$f" done which might still fail if there are directories matching the pattern for instance. You can overcome this by usi...

Thanks for the reply. All 3 suggestions correctly achieve the piping, but do not display the actual filename. I was after... Analog_Bass__Lead.vital "maniclout" Blackhole_Dimension.vital "Cobranix"
@carlcaulkett Ah missed that.
Perfect! The first example works just fine for me, and I can build on it 😀
I needed to add a comment containing more formatted code, so I was forced to add another question. In classic StackOverflow style, that question has now been deleted, without any explanation whatsover. Ironically, despite a message saying it was no longer visible, I was able to dimly see the text (very light grey on white!) and was able to copy it into the comment below. Of course I've lost the formatting.
I thought I could build on it. What I would like to do is to create a new folder based on the Author's name and copy the file into it. I've come up with the code... for f in *.vital; do ` echo -n "$f: “` ` d=$(jq '.author' "$f”)` ` eval mkdir $d` done I'm aware that I still need to think about what to do when the author folder has already been created and also how to get rid of the quotes around the author name before it gets passed into the mkdir, but one step at a time! The script fails to run, returning the error... for dquote cmdsubst dquote> Ideas?
@carlcaulkett you actually should have gotten a notice as you posted the question in the space reserved for answers. Please use the Ask Question button for new questions.
One way would actually be to run mkdir -p $(jq '.author' "$f” | tr -d \") which should take care of everything besides the file not containing an .author entry.
Fair enough. It would help if the formatting capabilities within comments were a little stronger. I know it's to discourage people from having massive, unruly comment threads, but it does get in the way, somewhat!
19:55
iirc, jq doesn't accept filename args, you should use < (input redirection)
JoL
JoL
Since they're using zsh, they can also select just the regular files using the . glob qualifier: *.vital(.)
@carlcaulkett If you need formatting capabilities in comments this usually is a good indication that the comment should have either been an edit to a post or a new question altogether. Comments are for clarification on posts, not for followup questions.
@Riad I can do, for instance, jq '.author' 729.vital and it works just fine.
@Riad man jq says jq [options...] filter [files...], so filenames are accepted.
@nohillside Are you saying that it is acceptable StackOverflow etiquette to go back and edit the original? Does this cover just adding sections? Not, presumably, changing the meaning of existing section... yonder way, madness lies, I would have thought! I'm not trying to be flippant, BTW, just trying to understand the SO mindset 😉
19:55
@carlcaulkett New problem, new question :-)
As it turns out, I got a working solution. The script is... for f in *.vital; do j=$(jq '.author' "$f") f=("$f") echo "$j $f" mkdir $j cp ./$f ./$j done Though, strangely enough, it only works if I copy and paste the command into my Terminal. If I run it as a .sh script it gives errors. I wonder if I need to zsh specific extension, or if I need a special shebang 🤷‍♂️

last day (15 days later) »