bash - “for i in *.mp4” how to not print “*.mp4” if it doesn't find any files? [duplicate]
Clash Royale CLAN TAG#URR8PPP
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?
bash shell-script
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.
add a comment |
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?
bash shell-script
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
add a comment |
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?
bash shell-script
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
bash shell-script
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
By setting the shell's nullglob
option: shopt -s nullglob
. From man bash
:
If no matching filenames are found, and the
shell optionnullglob
is not enabled, the word is left unchanged. If
thenullglob
option is set, and no matches are found, the word is
removed.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
By setting the shell's nullglob
option: shopt -s nullglob
. From man bash
:
If no matching filenames are found, and the
shell optionnullglob
is not enabled, the word is left unchanged. If
thenullglob
option is set, and no matches are found, the word is
removed.
add a comment |
By setting the shell's nullglob
option: shopt -s nullglob
. From man bash
:
If no matching filenames are found, and the
shell optionnullglob
is not enabled, the word is left unchanged. If
thenullglob
option is set, and no matches are found, the word is
removed.
add a comment |
By setting the shell's nullglob
option: shopt -s nullglob
. From man bash
:
If no matching filenames are found, and the
shell optionnullglob
is not enabled, the word is left unchanged. If
thenullglob
option is set, and no matches are found, the word is
removed.
By setting the shell's nullglob
option: shopt -s nullglob
. From man bash
:
If no matching filenames are found, and the
shell optionnullglob
is not enabled, the word is left unchanged. If
thenullglob
option is set, and no matches are found, the word is
removed.
edited Feb 8 at 5:54
filbranden
10.1k21645
10.1k21645
answered Feb 8 at 1:18
steeldriversteeldriver
36.4k35286
36.4k35286
add a comment |
add a comment |
shopt -s nullglob
– wjandrea
Feb 8 at 1:18