Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 356
  • Last Modified:

Linux Shell Scripting: Replace Slash

How can I replace all slashses with %2f
?
 f="abc/xyz/123"
 echo ${f}

Open in new window

The result should be:
abc%2fxyz%2f123
0
hankknight
Asked:
hankknight
3 Solutions
 
unknown_routineCommented:
$ bar=${f////%2f}


$ echo ${bar}
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
You mean to replace them in the string f ?

This will replace them:

f=`echo $f | sed 's/\//\%2f/g'`

echo ${f}

But I'm not getting why you would want this ;)
0
 
woolmilkporcCommented:
The first - elegant! - solution needs just a tiny correction:

f=${f//\//%2f}
echo $f
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now