So, the problem is - I have a list of files and I want to send them into a program, so it could handle this list in the same process. What I mean is, for example I have a bunch video files, that I want to play with mpv, but I need to pass them into a certain order which I can create with ls video\ * | sort -k2
. The name of each file looks like video [number] - [title].mp4
. I want to sort them by [number]
column so I call ls
and sort
programs, because my shell (zsh) can't do such thing by it self (I think).
So I typed ls video\ * | sort -k2
and it gave me a sorted list as I wanted it to. But when I'm trying to pass it into mpv with mpv $(ls video\ * | sort -k2)
, for some reason mpv doesn't read file names line by line, instead it reads them from space to space (I mean, it's not mpv's problem, it's the shell who's giving mpv such arguments separated by spaces but not lines).
I tried to wrap each line with quotes, tried to create a oneline list, tried both at the same time, but none if that worked. Shell always separates file names space by space, it ignores newlines or quotes. It's all because spaces, isn't?