5

Is there way of inserting a quote at the start and end into a string variable?

I have this variable say:

string="desktop/first folder"

If I echo this, it will display:

desktop/first folder

I need the string to be stored as:

"desktop/first folder"
6

If you don't do variable substitution, using single quotes as delimiters, so you can use double quotes in your string:

string='"desktop/first folder"'
6

In bash you can use \ as an escape character what whatever follows it. In your case, use it like this:

string="\"desktop/first folder\""

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.