I'm trying to write a for loop in bash to get the files with extension of jpg, jpeg, png, this i my attempt, but does not work
for file in "${arg}"/*.{jpg,jpeg,png}; do echo ${arg}-something.jpg > z.txt ; done;
basically, i want to get the name of the file with those extension in the current folder, and do something with each file, then output the filename back with a new extension.
Chaining multiple commands in the Bash for loop You obviously aren't limited to a single command in a for loop, you can chain multiple ones inside the for-loop. You can chain multiple commands with the ; semicolon, the last command will be the done keyword to indicate you're, well, done.
UPDATE: for all files in the same folder: first, get the folder path (on Windows, like this). Suppose it's "D:\my_data" . Then, you can get all the filepaths of the files as in the script above. Show activity on this post.
You are not using $file
anywhere. Try
for file in "$arg"/*.{jpg,jpeg,png} ; do
echo "$file" > z.txt
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With