0

I'm working on a bash script and for a part of the bash script I want to take the most recent file in a directory and make a new file in the same directory , but the new file should be increased by one. So for example if the most recent file is file1234.txt I want to create a new file in the directory called file1235.txt. So my code is as follows.

file=$(ls -ltr /home/dir |tail -n 1 | awk '{print $9}'  | cut -f1 -d "." | cut -c 5- )
echo $file

newfile=$((file +1 )) echo $newfile touch file$newfile.txt

The issue is that the new file that is created is file1.txt not file1235.txt. Is this an issue with subshells being created?

manhasnoname
  • 173
  • 2
  • 6
  • 12

0 Answers0