Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我date +%s直接在 unix 终端上运行命令时,它会正确执行并给出自 1970 年以来的秒数。
date +%s
但是,当同一命令位于脚本文件中时,请说 temp.sh,如下所示:
business_dt=date +%s echo $business_dt
在执行上述脚本时,它会引发如下错误:
-ksh: +%s: not found [No such file or directory]
如何解决这个问题?
您需要使用命令替换将命令的输出分配给变量。语法是var=$(command). 因此,尝试将脚本更改为:
var=$(command)
business_dt=$(date +%s)