Shell script - remove first and last quote (") from a variable

后端 未结 15 1726
刺人心
刺人心 2020-11-30 16:47

Below is the snippet of a shell script from a larger script. It removes the quotes from the string that is held by a variable. I am doing it using sed, but is it efficient?

15条回答
  •  [愿得一人]
    2020-11-30 17:28

    This is the most discrete way without using sed:

    x='"fish"'
    printf "   quotes: %s\nno quotes:  %s\n" "$x" "${x//\"/}"
    

    Or

    echo $x
    echo ${x//\"/}
    

    Output:

       quotes: "fish"
    no quotes:  fish
    

    I got this from a source.

提交回复
热议问题