How to replace spaces with %20 in a string using a bash script

When you try to build, for instance in a markdown file, a link to a local file whose name contains lot of white spaces, some parsers will not allow these white spaces and thus the local links will not be operational.

The small script presented bellow show how to replace white spaces in a ‘string’ passed in argument with %20 character:

#!/bin/bash
echo $1|sed -e 's/ /%20/g'
  • That’s it! Enjoy!
Slavisa Jovanovic
Slavisa Jovanovic
Associate Professor (Maitre de conférence HDR)

My research interests include circuits and systems for AI and energy harvesting circuits.