I'd like to create a small shell script that will tell me the duration of a video whose file name is passed to it as a parameter. It'd be something like this:
$ script_name "file name with spaces.webm" # or any other media file extension
The script file would resemble
#/bin/bash SECRET_SAUCE_USING_$1 | mediainfo | grep Duration | sort -u # maybe SECRET_SAUCE_USING_$1 | xargs -0 mediainfo . . .
On the command line, this is what works and what I want the script to do:
$ mediainfo file\ name\ with\ spaces.webm | grep Duration | sort -u
I've tried using things like
echo "$1" | sed 's/ /\\ /g' # piped to mediainfo . . .
to change the spaces in the file name to '\ ' character pairs (without the quotes). The echo ... | sed ... part works but mediainfo barfs
echo "$1" | tr ' ' '\000' | xargs -0 mediainfo . . .
to change the spaces to nulls and get xargs to invoke mediainfo with nulls in the file name instead of spaces.
I haven't found a solution so far. (I actually use zsh, not bash.) All help greatly appreciated. Tnx.