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