bash - “for i in *.mp4” how to not print “*.mp4” if it doesn't find any files? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1
















This question already has an answer here:



  • A star is being printed for an empty directory after running a script to list the subfolder

    1 answer



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?










share|improve this question













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















1
















This question already has an answer here:



  • A star is being printed for an empty directory after running a script to list the subfolder

    1 answer



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?










share|improve this question













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













1












1








1









This question already has an answer here:



  • A star is being printed for an empty directory after running a script to list the subfolder

    1 answer



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?










share|improve this question















This question already has an answer here:



  • A star is being printed for an empty directory after running a script to list the subfolder

    1 answer



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?





This question already has an answer here:



  • A star is being printed for an empty directory after running a script to list the subfolder

    1 answer







bash shell-script






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 8 at 1:14









jurdjurd

82




82




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.









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

















  • shopt -s nullglob

    – wjandrea
    Feb 8 at 1:18
















shopt -s nullglob

– wjandrea
Feb 8 at 1:18





shopt -s nullglob

– wjandrea
Feb 8 at 1:18










1 Answer
1






active

oldest

votes


















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.







share|improve this answer































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    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.







    share|improve this answer





























      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.







      share|improve this answer



























        2












        2








        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.







        share|improve this answer















        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.








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 8 at 5:54









        filbranden

        10.1k21645




        10.1k21645










        answered Feb 8 at 1:18









        steeldriversteeldriver

        36.4k35286




        36.4k35286












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay