Home > Enterprise >  How to remove initial dot from a string in a variable in bash
How to remove initial dot from a string in a variable in bash

Time:10-12

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.

CodePudding user response:

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'
  • Related