使用bash脚本文件重命名
我有一个包含大量照片的文件夹中执行bash脚本设置,依次缝合他们到基于用户输入的全景。一旦生成完成,输出文件重命名为 $ X-pano.jpg
和移动一个文件夹更高。
I have a bash script set that executes in a folder containing a number of photos and sequentially stitches them into panoramas based on the user input. Once the generation is completed, the output file is renamed to $x-pano.jpg
and moved one folder higher.
我的问题是多少preFIX是基于脚本的顺序执行,这意味着所有文件获得改名 1 pano.jpg
到正pano.jpg 。
My issue is the number prefix is based on the sequential execution of the script, meaning all files get renamed 1-pano.jpg
to n-pano.jpg
based on the number of panoramas generated during the script execution.
我如何修改重命名过程看存储文件夹,并获得最大的 $ X
?我想通过1递增,这个数字和文件的数值preFIX使用。我现在的code是
How can I modify the renaming process to look at the storage folder and get the largest $x
? I want to increment that number by 1 and use as the file's numerical prefix. My current code is
//get the list of files in directory and sort in increasing order
$filelist=$(find ../ -maxdepth 1 -type f | sort -n)
//get number of files
$length=${filelist[@]}
//get the last file
$lastFile=${fileList[$((length-1))]}
将得到的文件的列表,排序在递增的顺序,并从列表中的最后一个文件。这就是我会被卡住。使用 -
作为分隔符,我怎么能捕获当前值
will get a list of the files, sort in increasing order and get the last file from the list. This is where I get stuck. Using -
as a delimiter, how can I capture the current value?
您可能正在寻找的 $ {VAR %%富}
结构,这条最长的富
从变量的末尾
You're probably looking for the ${var%%foo}
construct, which strips the longest foo
from the end of a variable:
$ F=1-pano.jpg
$ echo ${F%%-pano.jpg}
1
$ F=1222-pano.jpg
$ echo ${F%%-pano.jpg}
1222
尝试 lastNum = $ {lastFile %% - pano.jpg}