0

I wanted to change the name of my file from file.txt to file_4i.txt and file_5i.txt according to the number I need but when I use the command below, the file name changes to file_.txt and the value of m never is indicated. I wanted to get 4i but $mi does not work either.

sudo sh -c "m=4 ; mv file.txt file_$mi.txt"
sudo sh -c "m=4 ; mv file.txt file_$m.txt"
vkaul11
  • 4,098
  • 12
  • 47
  • 79

1 Answers1

0

Use single quotes so the variable doesn't expand early, and use {} so mi isn't interpreted as the variable name:

sudo sh -c 'm=4 ; mv file.txt file_${m}i.txt'
sudo sh -c 'm=4 ; mv file.txt file_$m.txt'