I have an array and a function which list all files in a directory and initializes the array; however, that method is not working. Aparently b/c the variable is local to the function. How can I make it global, or what would be the correct way to pass it to the function without using return
Code:
list_files() {
files=($(ls | grep txt 2>/dev/null))
if [ $? -ne 0 ]; then
echo "error...."
exit 1
}
files=""
list_files
by the way, I know this will work just fine
Code:
files=($(ls | grep txt 2>/dev/null))
I wanted to use a function which output an error in case of an empty directory