简体   繁体   English

bash while循环,使用echo作为循环计数器

[英]bash while loop using echo as the loop counter

hello I have a command 你好,我有一个命令

echo $(ssh dema@10.0.1.100 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l')

this returns a integer value I need to while loop over it but can't seem to figure out who to do that. 这返回一个整数值,我需要在while循环上遍历,但似乎无法弄清楚是谁做的。

while echo $(ssh dema@10.0.1.100 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l') -g 1; do

echo stuff

done

Hi You can try like this, 嗨,您可以尝试这样,

declare -i value
value=`echo $(ssh dema@10.0.1.100 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l')`
while [ "$value" -gt 1 ]; do
    echo stuff
    value=`echo $(ssh dema@10.0.1.100 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l')`
done

OR we can use it like, 或者我们可以像这样使用它,

declare -i value
while : ; do
  value=`echo $(ssh dema@10.0.1.100 'zfs list -o name -t snapshot | grep tank/dema@Daily_$(date +"%Y-%m-%d") | wc -l')`
  [[ "$value" -gt 1 ]] || break
  echo stuff
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM