开发者

MacOS X terminal date and variable problem

I had this bat file in win that worked fine

set day=%date:~0,2%
set month=%date:~3,2%
set year=%date:~6,4%
set filename=hello-%anno%_%mese%_%giorno%开发者_如何学编程-world.txt
my-program.exe --report-file=%filename%

I've passed on MACOS X and I'm trying to have the same work using a *.commad file but I can not pass the date variable in the file name argument:

my-program --report-file= date "+%Y_%m_%d"

doesn't work! And I need to add the words 'Hello' and 'word.txt' in the filename!

Tried to use set and $1 but couldn't hang it over

set date "+%Y_%m_%d"
echo $1

echoes date

Any help will be appreciated!


In order to use the output of the date program, you need to use command substitution. You can do this either by surrounding it with backticks or parenthesis with a leading dollar sign.

my-program −-report-file=`date "%Y_%m_%d"`

or

my-program --report-file=$(date "%Y_%m_%d")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜