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.
    

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

  • 相关阅读:
    1.常用命令
    虚拟机共享文件夹
    Docker安装 和简单使用
    js方法名通过参数传递调用实例
    highcharts参数说明
    绘制HightCharts饼状图
    附加数据库失败,操作系统错误 5:”5(拒绝访问。)”的解决办法
    ckeditor相关使用
    针对MySQL提高百万条数据的查询速度优化
    SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
  • 原文地址:https://www.cnblogs.com/FengGeBlog/p/13027944.html
Copyright © 2011-2022 走看看