I have the folder testfolder/subfolder with content backup file1.txt file2.txt testFolder
And I have script testfolder/testMv.sh
Now I'm inside of the bash session and do the following:
echo "$SHELL" cd testfolder/subfolder echo "bla" > file1.txt echo "bla" > file2.txt mkdir trs ls mv "!(backup)" backup
/bin/bash backup file1.txt file2.txt trs
Work perfectly, all files and folder except backup moved, no error. Live is great.
Now put all the same to the testfolder/testMv.sh
echo "bla" > file1.txt echo "bla" > file2.txt mkdir trs ls echo mv "!(backup)" backup mv "!(backup)" backup
In the same bash, on the same machine doing:
cd testfolder/subfolder ../testMv.sh
backup file1.txt file2.txt trs mv !(backup) backup mv: cannot stat '!(backup)': No such file or directory
PS I know how to avoid usage of mv, I just want to understand why the sh script works in different way from the shell itself.