Shell 脚本中队列实现方式
先进先出,三种操作
- count: 计数
- enqueue:入队
- dequeue:出队
#!/usr/bin/env bash
array=()
# enqueue
array[${#array[@]}]=1
array[${#array[@]}]=2
array[${#array[@]}]=3
# count
echo "count: ${#array[@]}"
echo "${array[@]}"
echo "----------------"
# dequeue
array=(${array[@]:1})
# count
echo "count: ${#array[@]}"
echo "${array[@]}"
output:
count: 3
1 2 3
----------------
count: 2
2 3