D
D
Denis Kotlyarov2015-07-28 14:57:53
linux
Denis Kotlyarov, 2015-07-28 14:57:53

Linux, Bash, Replace characters in a variable?

How to replace characters in a variable, for example replace spaces with %20

Answer the question

In order to leave comments, you need to log in

4 answer(s)
L
littleguga, 2015-07-28
@denisandroid

${mystring//pattern/replacement}

myurl="test toster"
echo ${myurl// /%20}

A
Andrey Burov, 2015-07-28
@BuriK666

Judging by the number of questions on bash, I strongly advise you to read www.tldp.org/LDP/abs/html , there are answers to all your questions.

A
akr0, 2018-06-20
@akr0

I will supplement the previous comments, to replace the first match, the construction is used

myurl="test toster testarossa"
echo ${myurl/ /%20}
test%20toster testarossa

For those who have trouble with English, there is a good dock on www.opennet.ru
https://www.opennet.ru/docs/RUS/bash_scripting_guide/

E
Eugene, 2019-09-04
@Jekshmek

#!/bin/bash
sqlite3=`which sqlite3`
DB_FILE=words.db
echo "Enter word:"
read input_translate
input_translate=${input_translate//[^a-z0-9a-z,."'" ]/ }
$ sqlite3 $DB_FILE " insert into words (translate) values ​​(\"$input_translate\");"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question