sh 将当前日期附加到文件名字符串

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 将当前日期附加到文件名字符串相关的知识,希望对你有一定的参考价值。


use sed to search replace
https://askubuntu.com/questions/816321/problem-using-sed-to-replace-urls-in-html-files-with-script

check if previous command executed successfully
https://askubuntu.com/questions/29370/how-to-check-if-a-command-succeeded

append date to string
https://stackoverflow.com/questions/1401482/yyyy-mm-dd-format-date-in-shell-script

appending current date to filename or string
https://unix.stackexchange.com/questions/57590/appending-a-current-date-from-a-variable-to-a-filename


# shell function
# search for nextdoor.test, replace with nextdoor.ciwork.co 
# sql file is exported with date appended at the end
# thats why this script needs the date to match the exported sql file name

function updatedb() {
  # first execute the command
  sed -i -- "s#nextdoor.test#nextdoor.ciwork.co#g" "nextdoor_`(date +%F)`.sql"
  # now check if it was sucessful
  if [ $? -eq 0 ]; then
      echo "replaced nextdoor.test with nextdoor.ciwork.co"
  else
      echo "Unable to search and replace"
  fi
}






以上是关于sh 将当前日期附加到文件名字符串的主要内容,如果未能解决你的问题,请参考以下文章

如何将当前日期时间作为字符串附加到 RouteConfig.cs 中的 URL

雪花中的 Javascript 函数将表名附加到当前日期

如何在Javascript中获取当前格式化日期dd/mm/yyyy并将其附加到输入[重复]

将日期/时间戳附加到现有文件

如何将图像和时钟添加到 kv 文件

将日期附加到字符串以在 oracle 中获取表名并对其进行选择查询