【发布时间】:2016-08-28 12:03:27
【问题描述】:
与this OP 相同的问题,但必须是单独的原因。
以下脚本:
#!/bin/sh
arr=("cat" "dog" "bird")
以交互方式工作(debian),但在通过 crontab 调用时失败:
/bin/sh: 2: /path/zero_check.sh: Syntax error: "(" unexpected
我尝试使用#!/bin/bash shebang,并使用declare -a arr=("cat" "dog" "bird") 声明数组,但没有效果。
知道为什么吗?
【问题讨论】:
-
你如何在 crontab 中调用你的脚本?
-
错误信息清楚地表明 Bash 实际上并未用于执行脚本。
-
我尝试了两个 shebang,但只是将脚本复制到错误的不同点。以下解决方案有效。
-
bash或sh最适合 cron 吗? -
@geotheory 这真的取决于你想做什么。如果你需要数组,那么 Bash。