我有一個參數$1
,例如設置爲字符串operations/software/tools-manifest
,我想將其轉換爲字符串operations-software-tools-manifest
,即我。即用破折號(-
)替換所有斜槓(/
)。單獨使用bash
這可能嗎?例如sed(1)
?
我試過(unsucessfully):
[[email protected] ~]$ testparam=operations/software/tools-manifest
[[email protected] ~]$ echo "${testparam////-/}"
operations-/software-/tools-manifest
[[email protected] ~]$ echo "${testparam///-/}"
operations/software/tools-manifest
[[email protected] ~]$ echo "${testparam//\//-/}"
operations-/software-/tools-manifest
[[email protected] ~]$ echo "${testparam//\\//-/}"
operations/software/tools-manifest
[[email protected] ~]$ echo "${testparam//[/]/-/}"
operations/software/tools-manifest
[[email protected] ~]$ echo "${testparam//\x2f/-/}"
operations/software/tools-manifest
[[email protected] ~]$ echo "${testparam//\57/-/}"
operations/software/tools-manifest
[[email protected] ~]$
* argl *爲什麼我在測試中使用尾隨'/'?謝謝! –