Answer the question
In order to leave comments, you need to log in
How to change spaces to %20 in bash script?
I am writing a bash script that accepts a request via read, inserts it into a link and opens this link. You need to make sure that if the request contains spaces, then they are automatically changed to %20, since %20 is the space code. How to do it?
Answer the question
In order to leave comments, you need to log in
For example like this:
LINE="test test test"
LINE=$(echo $LINE | sed "s/ /%20/g")
echo $LINE
if in the future it is supposed to transfer this data via a URL, then replacing only spaces will obviously not be enough, for example, I use the jq
utility for this
example:
echo 'This works if x < y' | jq -Rr '@uri'
This%20works%20if%20x%20%3C%20y
read query
echo "$query" | jq -Rr '@uri'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question