I am having trouble getting the basics of Bash scripting down. Here's what I have so far:
#!/bin/bash
FILES="/home/john/my directory/*.txt"
for f in "${FILES}"
do
echo "${f}"
done
All I want to do is list all the .txt
files in a for
loop so I can do stuff with them. But the space in the my directory
and the asterisk in *.txt
just aren't playing nicely. I tried using it with and without double quotes, with and without curly braces on variable names and still can't print all the .txt
files.
This is a very basic thing, but I'm still struggling because I'm tired and can't think straight.
What am I doing wrong?
I've been able to successfully apply the script above if my FILES don't have a space or an asterisk... I had to experiment with or without the use of double quotes and braces to get it to work. But the moment I have both spaces and an asterisk, it messes everything up.