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 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')显示参数。我应该怎么做才能去掉这些引号?

最佳答案

为getopt使用选项-u--unquoted,即

if ! options=$(getopt -u -o : -l along:,blong:,clong: -- "$@")

getopt 的联机帮助页对 -u 说:

Do not quote the output. Note that whitespace and special (shell-dependent) characters can cause havoc in this mode (like they do with other getopt(1) implementations).

关于linux - 从shell脚本中的字符串中删除单引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13761874/

相关文章:

c++ - 用于运行高可靠性航天软件的特定 Linux 发行版?

linux - 如何杀死在后台 kubernetes 中运行的端口转发进程

python - 以编程方式获取 bash 完成选项

bash - 无法使用 Cron 删除文件

linux - 使用 printf 以特殊格式打印值

Linux非su脚本间接触发su脚本?

linux - Linux 用户空间上的 USB 插件检测

linux - 运行时意外的文件结尾

c - 当我不想覆盖时我的 shell 实现

bash - 在 Bash 中测试文件是否存在