reverse the order of characters in a string

后端 未结 13 1032
逝去的感伤
逝去的感伤 2020-12-04 15:03

In string \"12345\", out string \"54321\". Preferably without third party tools and regex.

13条回答
  •  独厮守ぢ
    2020-12-04 15:41

    Presume that a variable 'var' has the value '123'

    var="123"
    

    Reverse the string and store in a new variable 'rav':

    rav=$(echo $var | rev)
    

    You'll see the 'rav' has the value of '321' using echo.

    echo $rav
    

提交回复
热议问题