I've just started to use linux and bash. I wanted to know how to create a bash function that can add all the files that end with .conf that any user could read into a file. And for the files that a normal user cannot read to be added into another file. Im running it like this, but im getting this error code 4: Syntax error: "(" unexpected (expecting "}") '''
add_files () {
readable_file_list=()
unreadable_file_list=()
# Find all files with .conf extension
for file in /*.conf; do
# Check if file is readable by any user
if [[ -r "$file" ]]; then
# Add file to readable list
readable_file_list+=("$file")
else
# Add file to unreadable list
unreadable_file_list+=("$file")
fi
done
# Add readable files to readable_files.txt
printf '%s\n' "${readable_file_list[@]}" > readable_files.txt
# Add unreadable files to unreadable_files.txt
printf '%s\n' "${unreadable_file_list[@]}" > unreadable_files.txt
}
'''
Any ideas on why?