我可以一次在参数中创建两个(或更多)子站吗?

时间:2017-06-06 20:29:32

标签: bash shell replace

我想分别用@.替换每个\@\.。现在我用以下方法解决这个问题:

str="@foo.bar.baz"
str=${str//"."/"\."}
str=${str/"@"/"\@"}
echo $str

我可以缩短这个吗?

1 个答案:

答案 0 :(得分:2)

使用use re 'debug'; "The 39 Steps - a GREAT book - colours_15" =~ /([A-Z]+)/;

Compiling REx "([A-Z]+)"
Final program:
   1: OPEN1 (3)
   3:   PLUS (15)
   4:     ANYOF[A-Z][] (0)
  15: CLOSE1 (17)
  17: END (0)
stclass ANYOF[A-Z][] plus minlen 1 
Matching REx "([A-Z]+)" against "The 39 Steps - a GREAT book - colours_15"
Matching stclass ANYOF[A-Z][] against "The 39 Steps - a GREAT book - colours_15" (40 bytes)
   0 <> <The 39 Ste>         |  1:OPEN1(3)
   0 <> <The 39 Ste>         |  3:PLUS(15)
                                  ANYOF[A-Z][] can match 1 times out of 2147483647...
   1 <T> <he 39 Step>        | 15:  CLOSE1(17)
   1 <T> <he 39 Step>        | 17:  END(0)
Match successful!
Freeing REx: "([A-Z]+)"