I am trying to use variable in renaming a file. However, I when insert the variable to the beginning of the filename, things does not work as expected.
Here's the case, I have a file name test:
$ ls
test
and a variable
i=1
When adding the variable to the end or middle of filename, it works:
$ mv test test_$i
$ ls
test_1
When adding the variable to the beginning of filename, it doesn't work:
$mv test_1 test
$mv test $i_test
mv: missing destination file operand after 'test'
Try 'mv --help' for more information.
And even worse, when there is extension in my filename, the file will be removed.
$ touch test.try
$ ls
test.try
$ mv test.try $i_test.try
$ ls
(nothing!)
Can anyone explain this to me? Is it a bug or something I don't know?