JohnOldman wrote:
While fooling around I realized that it matters how you are using the variable:
echo $result leads to stripping of newlines while echo "$result" keeps the newlines.
You are exactly right here, although the details confused me. Bash is word splitting the output - that is to say any groups of characters in $IFS (usually space, tab and newline) are replaced by a single space.
echo $result word splits, while
echo "$result" preserves all the newlines (and tabs, if there are any).
The confusing detail was that $IFS had been modified to something else (i.e. did not include newline) in the Ubuntu installation. The quoted $result works fine in both cases. My script shows the video and audio streams in a DVD ripped VOB file, along with the aspect ratio and framerate, to pick settings for an ffmpeg encode:
#!/bin/bash
# Identify the characteristics of a video file using mplayer
for file in "$@" ; do
echo $file
result=$(mplayer -identify -frames 0 -v "$file" 2> /dev/null)
echo "$result" | grep -e "^VIDEO" -e "^AUDIO" -e "==>"
framerate=$(echo $result | grep -o "[0-9]*\.[0-9]* fps")
echo "framerate $framerate"
aspect=$(echo $result | grep -o "aspect [0-9]")
if [[ "$aspect" == "aspect 2" ]] ; then echo -n "Fullscreen (standard) " ; fi
if [[ "$aspect" == "aspect 3" ]] ; then echo -n "Widescreen " ; fi
echo $aspect
echo
doneJohnOldman wrote:
By the way, I really enjoy this stuff, so when you have a shell scripting or programming question (C, Java or Go) post it and I'll jump on it.
Thanks - this forum has never failed to provide a useful answer to my queries.