zoukankan      html  css  js  c++  java
  • bash中花括号{1..10}的注意事项

    bash shell中,我们执行echo {1..10},会打印1-10这些数字

    [root@localhost ~]# echo {1..10}
    1 2 3 4 5 6 7 8 9 10
    

    但是有个前提,这其中的{1..10}不能带上引号,单双引号,反引号都不行。这是花括号的实现限制,如果想仔细了解,man bash,搜索Brace Expansion看这样一段话

    Brace Expansion
           Brace expansion is a mechanism by which arbitrary strings may be generated.  This mechanism is similar to pathname expansion, but
           the filenames generated need not exist.  Patterns to be brace expanded take the form of an optional preamble, followed by  either
           a  series  of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript.  The
           preamble is prefixed to each string contained within the braces, and the postscript is then appended to  each  resulting  string,
           expanding left to right.
    
           Brace expansions may be nested.  The results of each expanded string are not sorted; left to right order is preserved.  For exam‐
           ple, a{d,c,b}e expands into `ade ace abe'.
    
           A sequence expression takes the form {x..y[..incr]}, where x and y are  either  integers  or  single  characters,  and  incr,  an
           optional increment, is an integer.  When integers are supplied, the expression expands to each number between x and y, inclusive.
           Supplied integers may be prefixed with 0 to force each term to have the same width.  When either x or y begins with a  zero,  the
           shell  attempts to force all generated terms to contain the same number of digits, zero-padding where necessary.  When characters
           are supplied, the expression expands to each character lexicographically between x and y, inclusive.  Note that both x and y must
           be of the same type.  When the increment is supplied, it is used as the difference between each term.  The default increment is 1
           or -1 as appropriate.
    

    我只是复制了一小段,详情可以自己翻看,总之记住这个就可以了。

  • 相关阅读:
    Pycharm 设置python文件自动生成头部信息模板
    Python3.0 调用HTMLTestRunner生成的报告中不能显示用例中print函数的输出
    Python3.0 操作MySQL数据库执行SQL语句
    js时间戳转为日期格式
    Vue脚手架(vue-cli)安装总结
    Vue的生命周期
    常用的ES6语法
    学习python登录demo
    CSS的垂直居中和水平居中总结
    CSS清除浮动方法总结
  • 原文地址:https://www.cnblogs.com/FengGeBlog/p/13027944.html
Copyright © 2011-2022 走看看