我正在制作一个脚本,需要循环通过一个文件的列表命名,如file1,file2,file3,都命名相同的后缀数字根据用户的输入增加。
所以我做了一个脚本,但是当我输入数字3时,她只在file1上循环,然后就停止了。为什么?
如何让它根据用户的输入循环遍历n个文件?
这是我的脚本:
#!/bin/bash
echo "Base name of machines to bring down:"
read vm
echo "Number of machines:"
read num
COUNTER=0
while [ $COUNTER -lt $num ]; do
num=$[$COUNTER+1]
VBoxManage controlvm $vm$num poweroff
let COUNTER=COUNTER+1
done发布于 2012-03-14 01:50:05
使用double paren进行算术:
#!/bin/bash
echo "Base name of machines to bring down:"
read vm
echo "Number of machines:"
read num
let COUNTER=1
while (( COUNTER <= num )); do
echo $COUNTER of $num
let COUNTER=COUNTER+1
done更新
我修复了脚本,所以计数器从1开始,而不是0。@toninoj似乎想从1开始,但在他的脚本中,他从0开始。
https://stackoverflow.com/questions/9689230
复制相似问题