我正在制作一个makefile以重命名其中带有随机数的文件(我是Shell脚本中的新手).我不明白为什么,但是当我运行文件$ rand时,它的值是'ANDOM'.当我在makefile之外运行它时,它会起作用.
I am making a makefile to rename files with a random number in it (I am a newbie in shell script). I don't understand why, but when I run the file $rand is given the value 'ANDOM'. When I run this outside of the makefile it works.
如果有帮助,我会在Mac os终端中运行它.
I run this in the Mac os terminal, in case it's helpful.
all: renamefiles renamefiles: rand=$RANDOM && mv myfile.css $rand-myfile.css && mv myotherfile.css $rand-myotherfile.css推荐答案
使用日期/时间戳记以便按日期顺序列出重命名的文件会更容易/更好吗?
Wouldn't it be easier/better to use a date/time stamp so that the renamed files are listed in date order?
对于要让shell看到的每个$,您需要在makefile中使用两个$符号.
You need to use two $ signs in the makefile for each $ that you want the shell to see.
因此:
all: renamefiles renamefiles: rand=$$RANDOM && \ mv myfile.css $$rand-myfile.css && \ mv myotherfile.css $$rand-myotherfile.css或者,带有日期/时间戳记:
Or, with date/time stamps:
all: renamefiles renamefiles: time=$$(date +'%Y%m%d-%H%M%S') && \ mv myfile.css $$time-myfile.css && \ mv myotherfile.css $$time-myotherfile.css更多推荐
在生成文件中使用$ RANDOM
发布评论