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

后端 未结 15 1746
刺人心
刺人心 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条回答
  •  Happy的楠姐
    2020-11-30 17:23

    If you're using jq and trying to remove the quotes from the result, the other answers will work, but there's a better way. By using the -r option, you can output the result with no quotes.

    $ echo '{"foo": "bar"}' | jq '.foo'
    "bar"
    
    $ echo '{"foo": "bar"}' | jq -r '.foo'
    bar
    

提交回复
热议问题