Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: alternative method for a simple for



On Sep 15, 12:54pm, d.henman wrote:
}
} (Method 1.) Note that I could not not use this method as shown below
}   $ zmv -p ffmpeg -o " -b 160k -i" '(*).wav' '$1.mp3'
} 
} because it puts two hypens, "--", between -i and filename, as below:
}      ffmpeg -b 160k -i -- song1.wav song1.mp3
}      ffmpeg -b 160k -i -- song2.wav song2.mp3

Yes, as the zmv doc says:

    -p PROGRAM
          Call PROGRAM instead of cp, ln or mv.  Whatever it does, it
          should at least understand the form
               PROGRAM -- OLDNAME NEWNAME
          where OLDNAME and NEWNAME are filenames generated by zmv.

So you need to satisfy those constraints.

    function wav2mp3 {
      [[ "$1" == "--" ]] && shift
      ffmpeg -b 160k -i ffmpeg -b 160k -i "$@"
    }

    zmv -p wav2mp3 '(*).wav' '$1.mp3'

} --------
} 
} (Method 2.) Likewise I could not use zargs, yet at least,
}      because replacements or expansions //l/r or :r didn't seem to work..
} 
} $ zargs --replace=arg -e.. -- *.wav .. ffmpeg -b 160k -i arg ${${file::=arg}//.wav/.mp3}

Close, but you need to delay the expansion of your ${...} expression
until zargs executes the command.  The way you wrote it, the parameter
substitution occurs before zargs is even run.  Quotes are needed:

    zargs --replace=arg -e.. -- *.wav .. eval \
      ffmpeg -b 160k -i '"arg"' '${${file::="arg"}//.wav/.mp3}'

However, it's pretty hard to get the quoting perfect with that eval
in there.



Messages sorted by: Reverse Date, Date, Thread, Author