Linux 在shell脚本中从字符串中删除单引号
这是我的shell脚本-Linux 在shell脚本中从字符串中删除单引号,linux,shell,Linux,Shell,这是我的shell脚本- if ! options=$(getopt -o : -l along:,blong:,clong: -- "$@") then # something went wrong, getopt will put out an error message for us exit 1 fi set -- $options while [ $# -gt 0 ] do case $1 in --along) echo "--along
if ! options=$(getopt -o : -l along:,blong:,clong: -- "$@")
then
# something went wrong, getopt will put out an error message for us
exit 1
fi
set -- $options
while [ $# -gt 0 ]
do
case $1 in
--along) echo "--along selected :: $2" ;;
--blong) echo "--blong selected :: $2" ;;
--clong) echo "--clong selected :: $2" ;;
esac
shift
done
当我运行脚本时,我得到以下输出-
./test.sh --along hi --blong hello --clong bye
--along selected :: 'hi'
--blong selected :: 'hello'
--clong selected :: 'bye'
问题是我不想用单引号('hi','hello','bye')显示参数。我应该怎么做才能去掉那些引号呢?使用选项
-u
或--unquoted
作为getopt,即
if ! options=$(getopt -u -o : -l along:,blong:,clong: -- "$@")
getopt的主页上显示了-u
:
不要引用输出。请注意,空格和特殊字符
(依赖于shell)字符在此模式下可能会造成严重破坏(就像
使用其他getopt(1)实现)
对getopt使用选项
-u
或--unquoted
,即
if ! options=$(getopt -u -o : -l along:,blong:,clong: -- "$@")
getopt的主页上显示了-u
:
不要引用输出。请注意,空格和特殊字符
(依赖于shell)字符在此模式下可能会造成严重破坏(就像
使用其他getopt(1)实现)
丑陋的快速解决方案:
echo”--沿所选方向:$2“| sed-es/\'//g
丑陋的快速解决方案:echo”--沿所选方向:$2“| sed-es/\'//g