I am trying to substitute ''2019-01-14'' to '2019-01-14' in a varible $STG. I tried various techniques

echo ${STG//''/'}
echo $STG | sed -e s/'\'\''/'\''/g

many more none of the equations are working.

  • Do you just want the variable to be set as '2019-01-14'? – Nasir Riley Jan 14 '19 at 23:23
  • yes I want the variable to be set as '2019-01-14'. Below all just echo or print the value but the variable still remains the same with double quotes at the end. – Bootham Deyyam Jan 15 '19 at 2:44
  • You're not being clear on what you want. If you want to set the variable as '2019-01-14' then just export STG=\'2019-01-14\'. If you do that then it doesn't remain the same with double quotes at the end. Otherwise, assign that value to another variable and call that one so that you don't need tr or sed or any other rigmarole to get the output that you want. You're complicating things where it isn't necessary. – Nasir Riley Jan 15 '19 at 3:02

escaping is working:

$ echo ${STG//\'\'/\'}

or you can use tr:

$ echo "$STG" | tr -s "'"

sed is overkill here, but working if you use quotes correctly:

$ echo "$STG" | sed -e "s/''/'/g"                        

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.