【问题标题】:Bash script concat strings command not found [duplicate]找不到 Bash 脚本连接字符串命令 [重复]
【发布时间】:2015-12-30 00:05:21
【问题描述】:

我正在尝试运行这个简单的 bash 脚本:

file_name=deploy
 echo "Init File NAme $file_name"
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
echo "Current Time : $current_time"

new_fileName="${file_name}${current_time}.zip"
echo "New FileName: $new_fileName"
#echo $new_fileName ./app/code/community ./app/code/local ./app/design/frontend/indigo ./app/design/frontend/default 
#zip $new_fileName ./app/code/community ./app/code/local ./app/design/frontend/indigo ./app/design/frontend/default 

但由于某种原因,我收到了:

Init File NAme deploy
Current Time : 2015.10.01-16.04.02
./ManualPack.sh: line 5: $'\r': command not found
.zip5.10.01-16.04.02

我知道它对于任何 bash 初学者来说都非常简单,但我尝试了相当长的时间,使用许多 Stack Overflow 线程使其工作,但输出保持不变。

【问题讨论】:

  • 它在我的 linux 服务器上运行良好。你复制/粘贴了吗?也许有一些看不见的角色在惹你生气(比如\r)。试着手写一遍,不要复制/粘贴。

标签: bash


【解决方案1】:

您的文件中似乎有 Windows 样式的行终止符 (\r\n)。使用dos2unix 转换文件应该会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-10
    • 2020-10-10
    • 2021-03-09
    • 2015-08-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-17
    相关资源
    最近更新 更多