First, this is my first bash script. Second off, it works. Third, its pretty pointless. Those caveats outta the way, my desire was to have a way to rename every file in a directory that was a certain extension, into files like <user selected string>1.extention. The directory where this takes place usually contains ~25 different files in the format of [UniqueUnintuitiveLabel]_Complicated_and_Long_Name_01_[38281809].foo or such. I just wanted something to instantly change all those ~25 filenames into something with a simpler name I could perform commands on, like a1.foo, a2.foo, a3.foo etc.
Anyways, this is the solution I came up with...
Code:
#!/bin/bash
echo "Enter the number of files:"
read foocount
echo "Enter an easy to type base name, such as an anacronym:"
read simple
echo "Enter the file extension(with period):"
read exten
#create a temporary file to contain all filenames
#of the user defined extention in the current directory
ls *"$exten" >> tempfile
#for each unmodified file name, create a symbolic link
#of the form <userdefinedname>1.
n=1
while [ $n -le $foocount ]
do
filenamen=$(sed -n "$n{p;q;}" "tempfile")
ln -s $filenamen $simple$n
n=$((n+1))
done
rm tempfile
Is there a simpler/more elegant way to accomplish this? In particular, I have a feeling theres a way to get around the need for a stdout filled tempfile.
Symbolic links were used instead of "mv" because I need the original files to keep their names.
I know that TAB completion makes this script pretty useless, I really just wanted to learn some bash scripting.
Thanks.