Here is a better way to loop over files as it handles spaces and newlines in file names:
#!/bin/bash
find . -type f -iname "*.txt" -print0 | while IFS= read -r -d $'\0' line; do
echo "$line"
ls -l "$line"
done
More Related Contents:
- sh: 1: Syntax error: "(" unexpected error
- Iterate over a list of files with spaces
- ./configure : /bin/sh^M : bad interpreter [duplicate]
- How to declare 2D array in bash
- Defining a variable with or without export
- What does $@ mean in a shell script?
- The ‘eval’ command in Bash and its typical uses
- Better way to rename files based on multiple patterns
- Syntax error in shell script with process substitution
- Raise error in a Bash script
- Linux: copy and create destination dir if it does not exist
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
- How to run a shell script on a Unix console or Mac terminal?
- How to preserve line breaks when storing command output to a variable?
- How to use sed to remove the last n lines of a file
- Use sudo without password INSIDE a script
- Passing variables in remote ssh command
- How do I run multiple background commands in bash in a single line?
- Round a divided number in Bash
- Execute command after every command in bash
- How do I change bash history completion to complete what’s already on the line?
- Bash: wait with timeout
- Multithreading in Bash [duplicate]
- Randomly shuffling lines in Linux / Bash
- Running shell script in parallel
- Difference between shell and environment variables
- Replacing Control Character in sed
- SUID not working with shell script
- Counter increment in Bash loop not working
- How to pass parameters to a Bash script?