Hello,
I'm trying to do a bash script that checks a variable against a list of unwanted characters, e.g. to parse a file name.
This doesn't really sound like a difficult task, but for some reason, whatever I've tried so far does not work, including my last attempt, shown below. Perhaps I'm doing something silly here - and I'm getting tired of it. What would be the best way for instance to parse a file name for invalid characters, or to accomplish or fix the below?
#!/bin/bash
read -p "Enter a filename: " fname
invalid_chars=", . ! @ # \$ % ^ & \* ( ) + = ? { } [ ] | ~"
i=0
while (( i <= ${#fname} )); do
char=${fname:$i:1}
for char in `echo $invalid_chars`; do
echo "$char"
done
(( i += 1 ))
done
Thanks.