Graceful degradation for nudging at the terminal

Whenever a ball pattern match fails, it stops all work. For example,

$ mv *.jpg *.png folder1 && blahblah
mv: cannot stat `*.jpg': No such file or directory

      

*. png doesn't move to folder1, and blahblah doesn't start.

And the below script only works when both. [Az] * and * are doing well.

#!/bin/bash
cd $1
du -sk .[A-z]* *| sort -rn | head

      

How do I get globbing to fail gracefully, only displaying warnings at best, but never stopping?

+2


source to share


2 answers


In Bash, a shopt -s nullglob

failing globe will resolve without any error.



+5


source


then use a loop. KISS



for files in jpg png
do
  mv *.${files} /destination 2>/dev/null && do_something 
done

      

0


source







All Articles