1

I'm writing a script to print resolutions of my media files using MediaInfo. I hard coded the marvel directory in just for testing and getting the cuts right.

Code:

#!/bin/bash

for i in /mnt/D/tv/"Marvel (MCU)"/{*.mp4,*.mkv,*.avi,*.m4v}; do 
    mediainfo "$i" > temp
    H=`cat temp | grep "Height" | cut -d ":" -f 2 | cut -c 2- | cut -d "p" -f 1`
    W=`cat temp | grep "Width" | cut -d ":" -f 2 | cut -c 2- | cut -d "p" -f 1`
    printf "%-50s %s x %s \n" "$(basename "$i")" "$W" "$H"
    rm temp
done

Output:

1. Iron Man.mp4                                    1 920  x 800  
10. Guardians of the Galaxy.mp4                    1 280  x 536  
... 
8. Thor The Dark World.mkv                         1 920  x 800  
9. Captain America The Winter Soldier.mkv          1 280  x 534  
*.avi                                               x  
*.m4v                                               x  

There are only .mp4 and .mkv files in this folder, so it printed "*.avi" and "*.m4v." How can I suppress the printing of the extensions that it didn't find?

marked as duplicate by Community Feb 8 at 1:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • shopt -s nullglob – wjandrea Feb 8 at 1:18
2

By setting the shell's nullglob option: shopt -s nullglob. From man bash:

If no matching filenames are found, and the shell option nullglob is not enabled, the word is left unchanged. If the nullglob option is set, and no matches are found, the word is removed.

Not the answer you're looking for? Browse other questions tagged or ask your own question.