I have an array with name VERSION that I take from mydir directory and it has parameters(files) as below:
VERSION[0]="TEST01_0.TEST01_1"
VERSION[1]="TEST03_1"
VERSION[2]="TEST02_1.TEST02_2"
VERSION[3]="TEST04_2"
VERSION[4]="TEST02_3"
And I was trying to rename TEST01_0.TEST01_1 as TEST01_1 and TEST02_1.TEST02_2 as TEST02_2.But I am getting some error as below:
mv: cannot stat `TEST01_0.TEST01_1': No such file or directory
mv: cannot stat `TEST02_1.TEST02_2': No such file or directory
Can you please help me to fix it? Here is my code block:
#!/bin/sh
VERSION=(/mydir/TEST*)
for file in "${VERSION[@]}"
do
if [[ `echo ${file} | grep -o '_' | wc -l` == 2 ]]; then
mv "${file}" "${file%.*}";
fi
done
Thanks
#! /bin/sh? How are you running the file?bash test.shmydir?VERSIONhasTEST01_0.TEST01_1,TEST03_1, etc., butVERSION=(/mydir/TEST*)will mean it has/mydir/TEST01_0.TEST01_0,/mydir/TEST03_01, etc. Even so, the files should exist. Is this actually what you're running? What doesbash -x test.shoutput?VERSION[0]=".TEST01_1" VERSION[1]="TEST03_1" VERSION[2]="TEST02_2" VERSION[3]="TEST04_2" VERSION[4]="TEST02_3"