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.
    

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

  • 相关阅读:
    第2天 轻量级RPC框架开发
    028_ajax的String,View,Object执行流程
    027_获取隐藏id值的两种方式
    009_myBatis删除多条记录open="(",写成了index="(".
    026_一次性删除多条数据的sql语句
    025_json请求头与form表单请求头?
    024_如何生成一个32位的uuid?
    023_如何实现一次性删除多条记录?
    022_同步请求与异步请求的区别?
    021_SpringMVC中拦截器的作用?
  • 原文地址:https://www.cnblogs.com/FengGeBlog/p/13027944.html
Copyright © 2011-2022 走看看