1

I have a variable named myVar in bash with value as shown below.

'./favicon.png' './inc/sendEmail.php' './index.html' './images/header-background.jpg'

Note: the above code is the value of one variable

And I want want to change it to the below string by removing initial dot from each path

'/favicon.png' '/inc/sendEmail.php' '/index.html' '/images/header-background.jpg'

I am not able to figure out how to do this. Please help.

2
  • 2
    That's possible, for example using sed "s/'\./'/g" <<< "$string", but if you have any control over whatever generates the string, you should fix it where it's created, and also use an array instead of a string with hardcoded quotes, as any further processing tends to be more difficult with what you have. Commented Oct 9, 2022 at 15:11
  • 1
    Is the dot in xyz./abc to be removed as well? Commented Oct 9, 2022 at 15:36

1 Answer 1

2

With a bash parameter expansion?

#!/bin/bash

myVar="'./favicon.png' './inc/sendEmail.php' './index.html' './images/header-background.jpg'"

echo "${myVar//.\///}"
'/favicon.png' '/inc/sendEmail.php' '/index.html' '/images/header-background.jpg'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.