Change all ? in filenames to _
by Flexico from LinuxQuestions.org on (#4T6BF)
I'm trying to write a Bash script to get rid of Windows-illegal characters on my external drive since Windows implodes if it finds one. XD In the past I made the following script to change file name extensions:
Code:#!/bin/bash
for f in *.png; do
mv -- "$f" "${f%.png}.jpg"
echo "$f"
done...but my attempts at modifying it to look for a particular character in the middle of a file name have failed. I'm not too familiar with the syntax of it, so I could use some guidance.
Code:for f in *?*; do
#mv -- "$f" "${f%?}_${?%f}"
#echo "$f"
echo "${f%?}_${?%f}"
done


Code:#!/bin/bash
for f in *.png; do
mv -- "$f" "${f%.png}.jpg"
echo "$f"
done...but my attempts at modifying it to look for a particular character in the middle of a file name have failed. I'm not too familiar with the syntax of it, so I could use some guidance.
Code:for f in *?*; do
#mv -- "$f" "${f%?}_${?%f}"
#echo "$f"
echo "${f%?}_${?%f}"
done