bash 如何在 unix 中附加文件名与字符串和当前日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16983255/
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
How to append a file name in unix with a String and Current Date
提问by P.R
I have 4 names (AA,BB,CC,DD) in a config file. This has been used in a script.
我在配置文件中有 4 个名称(AA、BB、CC、DD)。这已在脚本中使用。
I am trying to get the output to be saved as
我正在尝试将输出保存为
Source_Server_Path="/dev/FtpData_Files/START_STOP_""_"$Current_Date""
where $1will be any one in the names.
其中,$1将名称中的任何一个。
$Current_Datehas to be in the format 05Jun2013.
$Current_Date必须采用 05Jun2013 格式。
回答by Adrian Frühwirth
$ foo="/bar/quux/$(date +%d%b%Y)"
$ echo "${foo}"
/bar/quux/07Jun2013
See also man date.
另见man date。
回答by Debaditya
Sample script/method ... Try if it helps
示例脚本/方法...试试看是否有帮助
config.txt
配置文件
AA,BB,CC,DD
Script.sh
脚本文件
file=
config=`cat $file | awk -F "," '{print }'`
#It will take AA .. whatever parameter you pass
Current_Date=`date +%d%b%Y`
echo START_STOP_"$config"_"$Current_Date"
How to run
怎么跑
sh script.sh config.txt
Output
输出
START_STOP_AA_07Jun2013

