I am trying to rename some files, with the information of other files with the same name but other ending. The string comparison within the for loops is completely ignored. No matter if I use ==, which should give me the desired result or !=, which should return nothing. Here is an example script:
for file in *.bz2; do
fullname="$file"
extension="${fullname#*.}"
filename="${fullname%.out.*}"
for tfile in *.txt; do
tfullname="$tfile"
tfilename="${tfullname%.*}"
if [ $filename==$tfilename ]; then # this satement is ignored, also when I try != it gives me the same result!
echo $tfilename
wcn=$(wc -l "$tfullname")
n=$(expr "$wcn" : '^[^0-9]*\([0-9]*\)')
echo "mv -i "${fullname}" "${filename}_files_${n}.${extension}""
fi
done
done
Here is the output, independent of the expression in the if statement:
text1
mv -i text1.out.bz2 text1_files_3.out.bz2
text2
mv -i text1.out.bz2 text1_files_7.out.bz2
text3
mv -i text1.out.bz2 text1_files_8.out.bz2
text1
mv -i text2.out.bz2 text2_files_3.out.bz2
text2
mv -i text2.out.bz2 text2_files_7.out.bz2
text3
mv -i text2.out.bz2 text2_files_8.out.bz2
text1
mv -i text3.out.bz2 text3_files_3.out.bz2
text2
mv -i text3.out.bz2 text3_files_7.out.bz2
text3
mv -i text3.out.bz2 text3_files_8.out.bz2
And here would be the desired output:
text1
mv -i text1.out.bz2 text1_files_3.out.bz2
text2
mv -i text2.out.bz2 text2_files_7.out.bz2
text3
mv -i text3.out.bz2 text3_files_8.out.bz2
What am I doing wrong?