sed plus sign doesn't work

后端 未结 4 1436
你的背包
你的背包 2020-12-01 15:53

I\'m trying to replace /./ or /././ or /./././ to / only in bash script. I\'ve managed to create regex for sed but it doe

4条回答
  •  自闭症患者
    2020-12-01 16:14

    You can also do this with bash's built-in parameter substitution. This doesn't require sed, which doesn't accept -r on a Mac under OS X:

    variable="something/./././"
    a=${variable/\/*/}/                   # Remove slash and everything after it, then re-apply slash afterwards
    echo $a
    something/
    

    See here for explanation and other examples.

提交回复
热议问题