bash 在bash脚本中存储日期变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21721875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Store date variable in bash script
提问by Gopu
I want to store date values into a variable for future use. Please correct the sample script:
我想将日期值存储到一个变量中以备将来使用。请更正示例脚本:
#!/bin/bash
Now_hourly = $(date +%d-%b-%H_%M)
Now_daily = $(date +%d-%b-daily)
echo $(Now_hourly)
echo $(Now_daily)
The output should be :
12-Feb-17_50
and
12-Feb-daily
But When I run the script, I am getting below error :Now_hourly: command not found
Now_daily: command not found
输出应该是:
12-Feb-17_50
并且
12-Feb-daily
但是当我运行脚本时,出现以下错误:Now_hourly: command not found
Now_daily: command not found
回答by MLSC
you can change the script like:
您可以更改脚本,如:
#!/bin/bash
Now_hourly=$(date +%d-%b-%H_%M)
Now_daily=$(date +%d-%b-daily)
echo "$Now_hourly"
echo "$Now_daily"
I think the problem is spaces around =
我认为问题是周围的空间 =
output:
输出:
12-Feb-12_03
12-Feb-daily