我想将数组的内容与文件的内容进行比较。我想最好的解决方案是:
b=( some data )
a=$(<file)
if [ $a -ne ${b[@]} ]
then
echo "variables are different"
fi
我说错了吗?
答案 0 :(得分:2)
试试这个:
$ cat file
a
b
c
$ echo -n "arrays are "
$ x1=( a b c )
$ mapfile -t x2 < file
$ [[ ${x1[@]} == ${x2[@]} ]] && echo "identical" || echo >&2 "different"
答案 1 :(得分:-1)
使用Bash的流程替换:
b=( some data )
if ! diff <(echo ${b[*]}) file; then
echo "different"
fi