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?

marked as duplicate by DarkHeart, l0b0, ilkkachu shell-script Mar 14 at 8:38

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.