Shell programming exercise: write a shell script, the script can delete the number in the file name of a file

Write a Shell script that can delete the number in the file name of a file.

#!/bin/bash
echo "Enter a filename:"
read FileName
newFileName=""
i=0
while [ $i -lt ${#FileName} ]
do
    char=${FileName:i:1}
    if [[ $char =~ [^0-9] ]]; then
        newFileName=$newFileName$char
    fi
    let i=i+1
done
mv $FileName $newFileName

Note:
1. -lt cannot be written as <.
2. There must be spaces at both ends of the =~ symbol that matches the regular expression, and the assignment number = cannot have spaces at both ends.
3. If the comment at the beginning is

#!/bin/sh

It may prompt "Bad Substitution".

Guess you like

Origin blog.csdn.net/COFACTOR/article/details/115255869