从字符串中删除一个字符

use*_*517 3 linux bash awk cut sed

我只是想%从变量中删除一个符号,所以我可以对结果进行数学计算.我尝试了几件事,但似乎都没有效果:

$ output="23%"
# usep=$(echo $output | awk '{print $1}' | cut -d '%' -f 1)
# usep=`echo $output | sed 's/\%//g`
# usep=`echo $output | head -c 2`
Run Code Online (Sandbox Code Playgroud)

变量usep仍包含该%字符.有任何想法吗?

Rub*_*ens 6

您可以使用POSIX参数替换:

$ output="23%"
$ usep=${output%%\%}
$ echo $usep
23
Run Code Online (Sandbox Code Playgroud)