August 19th, 2014

Passing variable outside of while loop in bash

This is throw away code.

But it shows how to pass a variable outside of a while loop in bash:

find . -type f -size +1000k -print0 | {
while IFS= read -r -d '' file; do
        FOO="$FOO `stat -r "$file" | gawk '{print $8}'| tr '\n' ' '`"   # Return the size without a new line at the end
        FOO="$FOO `echo  \"$file\"`\n"                                  # Return the file name WITH a new line at the end
echo -ne "$FOO" | sort -rn      # return sorted results