Bash - catch the output of a command -
i trying check output of command , run different commands depending on output.
count="1" f in "$@"; base=${f%.*} # if [ -e "${base}_${suffix}_${suffix2}.mp4" ]; echo -e "reading gps metadata using mediainfo file ${count}/${#@} "$(basename "${base}_${suffix}_${suffix2}.mp4")" mediainfo "${base}_${suffix}_${suffix2}.mp4" | grep "©xyz" | head -n 1 if [[ $? != *xyz* ]]; echo -e "warning!!! no gps information found! file ${count}/${#@} "$(basename "${base}_${suffix}_${suffix2}.mp4")" || exit 1 fi ((count++)) done mediainfo command checking output of. if video file has "©xyz" atom written output looks this:
$ mediainfo file | grep "©xyz" | head -n 1 $ ©xyz : +60.9613-125.9309/ $ otherwise null
$ mediainfo file | grep "©xyz" | head -n 1 $ the above code not work , echos warning when ©xyz presented. ideas of doing wrong?
the syntax using capture output of mediainfo command plain wrong. when using grep can use return code (the output of $?) directly in if-conditional
if mediainfo "${base}_${suffix}_${suffix2}.mp4" | grep -q "©xyz" 2> /dev/null; .. the -q flag in grep instructs run command silently without throwing results stdout, , part 2>/dev/null suppresses errors thrown via stderr, if-conditional pass when string present , fail if not present
Comments
Post a Comment