#!/bin/bash for i in {1..$1} do echo $i done
这样当用参数2调用时返回{1..2},而不是执行脚本并给我
1 2
Brace Expansion
A sequence expression takes the form {x..y},where x and y are either integers or single characters. …
Brace expansion is performed before any other expansions,and any characters special to other expansions are preserved in the result. It is strictly textual. Bash does not apply any syntactic interpretation to the context of the expansion or the text between the braces.
A correctly-formed brace expansion must contain unquoted opening and closing braces,and at least one unquoted comma or a valid sequence expression. Any incorrectly formed brace expansion is left unchanged.
尝试以下其中一种:
for ((i = 1; i <= $1; i++)); do echo $i done # Not recommended with large sequences. for i in $(seq 1 $1); do echo $i done
原文地址:https://www.jb51.cc/bash/387324.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。