- #1
sunmaz94
- 42
- 0
Homework Statement
Write a bash shell script to do the following:
# This shell script renames all files in the current
# directory, removing all vowels in the names.
# if the resultant name would lack any characters (excluding the extension)
# The file is not renamed. Also does not attempt to rename files that have no vowels.
Homework Equations
None.
The Attempt at a Solution
I do not understand why this line of code doesn't work:
Code:
new_name_no_ext=`echo $voweless_name | sed -e "s/\.[^\.]+$//"`
The above line should assign to $new_name_no_ext the string $voweless_name, without an extension. I am quite positive that the regex used is correct.
The entire program is:
Code:
#!/usr/bin/bash
# This shell script renames all files in the current
# directory, removing all vowels in the names.
# if the resultant name would lack any characters (excluding the extension)
# The file is not renamed. Also does not attempt to rename files that have no vowels.
for filename in * #Traverse all files in the current directory
do
current_name=$filename #Get the filename
voweless_name=`echo $current_name | sed -e "s/[aeiou]//g"` #Substitute vowel for nothing using sed
new_name_no_ext=`echo $voweless_name | sed -e "s/\.[^\.]+$//"`
echo "$new_name_no_ext"
#if [ `echo $voweless_name | sed -e "s/\.([^\.]+)$//"` != "" -a "$current_name" != "$voweless_name" ] #Rename iff the new nane is non-empty and is not identival to the current name
if [ "$new_name_no_ext" != "" -a "$current_name" != "$voweless_name" ] #Rename iff the new nane is non-empty and is not identival to the current name
then
mv "$current_name" "$voweless_name" #Do the actual renaming
fi
done
Any idea as to what is wrong?
Thanks in advance.