我有以下代码:
n=1
a_letters=("a" "b" "c" "d" "e")
while [ $n -le 3 ]; do
uniqueLetters=($(printf '%s\n' "${a_letters[@]}"))
rand=$[ ( $RANDOM % 5)]
echo "${uniqueLetters[$rand]}"
n=$(( $n+1 ))
done
如何避免已打印的数组项?
答案 0 :(得分:0)
你必须做一些簿记:
2种可能性:
我会选择选项1:
SELECT a.*
b.*
FROM cabinets a
LEFT JOIN (
SELECT *
FROM photos
WHERE a.cabid = b.cabid
ORDER BY b.ismain DESC
LIMIT 1) b
ON a.cabid = b.cabid
WHERE a.valid = 1
ORDER BY a.cabid
(未测试的)。
它的作用是从数组n=1
a_letters=("a" "b" "c" "d" "e")
while [ $n -le 3 ]; do
uniqueLetters=($(printf '%s\n' "${a_letters[@]}"))
rand=$[ ( $RANDOM % ${#a_letters[@]})]
echo "${uniqueLetters[$rand]}"
a_letters=( "${a_letters[@]/${uniqueLetters[$rand]}}" )
n=$(( $n+1 ))
done
中删除所选字符,并使用随机数组大小,以便自动更正减少的数组大小。