0

How can the script below be made to always work no matter the filenames returned by find ?

#!/bin/sh

cmds_should_always_work() { 
    echo "\n\n*********************************" $1
    stat --printf='%n' -- "$1" || echo STATFAILED
    echo "\n----------------\n"
    lsattr -d -- "$1" || echo LSATTRFAILED
    echo "\n----------------\n"
}; 
for item in $(find "$1" -maxdepth 1 -mindepth 1); do cmds_should_always_work "${item}"; done

For example files in the find directory that contain a new line break this script.

Further if the find directory is named e.g. $schema, this script returns the parent directory. How can this be avoided by the script vs. having to supply and escaped path somepath/\$schema to the script?

Prvt_Yadav
  • 5,732
  • 7
  • 32
  • 48
TrevTheDev
  • 157
  • 1
  • 8
  • 3
    Try to use `exec` option of find instead of `for` loop. – Prvt_Yadav Mar 14 '19 at 02:21
  • 3
    The options are pretty much covered in [Why is looping over find's output bad practice?](https://unix.stackexchange.com/questions/321697/why-is-looping-over-finds-output-bad-practice) – steeldriver Mar 14 '19 at 02:30

0 Answers0