[英]How do I append a string to the end of an array (list) in bash?
我一直在研究一個 bash 腳本,它應該循環遍歷您應該擁有的用戶列表和系統上的用戶列表。 我目前正在嘗試將存儲在變量中的用戶名稱添加到數組(列表)的末尾。 這是我的代碼正在做的事情:
for x in array
do
for y in otherArray
do
if [[ $x == $y ]]
then
newArray += $x
elif [[ $x != $y ]]
then
otherNewArray += $x
fi
done
done
這將返回此錯誤:
line [Insert line where I use =+ here] [Insert value of x here] command not found
有誰知道為什么會這樣?
有誰知道為什么會這樣?
這是對名為echo
變量的賦值:
echo=some_value
這將運行一個名為echo
的命令,其中包含兩個參數=
和some_value
。
echo = some_value
下面以同樣的方式運行一個名為newArray
的命令
newArray += $x
下面添加了一個新的數組元素:
newArray+=("$x")
下面將$x
的結果附加到數組中的第一個元素:
newArray+=$x
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.