首页 > 解决方案 > 用户指定的变量作为 shell 脚本循环中的计数器

问题描述

我想使用用户定义的计数器变量来操纵循环行为。我尝试将变量作为参数传递,并尝试在脚本本身中对它们进行硬编码,但没有任何效果。

#!/bin/bash

start_hour=0 #can be passed as argument ($1)
end_hour=24 #can be passed as argument ($2)

for i in {$((end_hour))..$((start_hour))}
do
        echo $i
done

输出{24..0}

标签: shellsh

解决方案


推荐阅读