我希望我的脚本定义一个空数组。如果预定义条件成立,则应添加数组值。为此我所做的是
declare -a FILES
file_count=0
if [ "$file_ext" != "$SUPPORTED_FILE_TYPE" ] ; then
echo "$file_ext is not supported for this task."
else
$FILES[$file_count] = $filename
file_count=$file_count+1
fi
执行这个脚本时我收到一些这样的错误
linux-softwares/launchers/join_files.sh: 51: [0]: not found
当数组中的设置数据不能用 $ 调用时:
declare -a FILES
file_count=0
if [ "$file_ext" != "$SUPPORTED_FILE_TYPE" ] ; then
echo "$file_ext is not supported for this task."
else
FILES[$file_count]=$filename
file_count=$file_count+1
fi
不带 $ 的文件。
这对我有用:
#!/bin/bash
declare -a FILES
file_count=0
file_ext='jpg'
SUPPORTED_FILE_TYPE='jpg'
filename='test.jpg'
if [ "$file_ext" != "$SUPPORTED_FILE_TYPE" ] ; then
echo "$file_ext is not supported for this task."
else
FILES[$file_count]=$filename
file_count=$(($file_count+1))
fi
如您所见,对数学运算进行了一些修改 $(( )),但 FILES 分配是相同的......
正如经过大量测试后所指出的,Ubuntu 默认 shell 似乎是 dash,这引发了错误。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)