Quantcast
Viewing latest article 10
Browse Latest Browse All 14

Shell – String replace

Previously we talked about how to submit a Google Form by the curl command.

 

In the url, we have to encode the special characters such as whitespace. In shell script, we could do string replace as follow.

${VariableName//Pattern/Replacement}

 

Here is an example.
string_replace.sh

#!/bin/sh

text="Hello World"

echo "${text}"
echo "${text// /%20}"

 

Check it out.
Image may be NSFW.
Clik here to view.
shell-replace-string

 

So now if you integrate the Google Forms submission in your backend, you could make sure the whitespace are all replaced by %20.

Done =)

Reference: nixCraft – Bash Script Replace Empty Spaces String


Filed under: Shell Script Tagged: Google Forms, nixCraft, Shell Script Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing latest article 10
Browse Latest Browse All 14

Trending Articles