Properly using redirection in script
by SlowCoder from LinuxQuestions.org on (#5DDN2)
I have the following script:
Quote:
$allFiles contains a list of files. I am trying to prepend the file size for each file. I've tried the 3 lines at the bottom, and I just cannot get it to work without 'stat' erring. I'm sure it's in the redirection methods I'm using.
Disclaimer: I'm sure there are plenty of utilities that do what I want. But I'm using this as an exercise to learn more about scripting, and in this case, redirection.


Quote:
#!/bin/bash dir1=$(printf '%q' "$1") echo Cataloging files that exist inside "$dir1" # get list of all files within requested directory allFiles=$(find "$1" -type f) # get total number of files numFiles=$(wc -l <<< "$allFiles") echo Total files: "$numFiles" # ERRORS START HERE #echo $("$allFiles" | printf '%q' | stat -c "%10s %n") #echo $(stat -c "%10s %n" <<< printf '%q' "$allFiles") #echo $(printf "%q" "$allFiles" | stat -c "%10s %n") |
Disclaimer: I'm sure there are plenty of utilities that do what I want. But I'm using this as an exercise to learn more about scripting, and in this case, redirection.