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
LVL 16
hankknightAsked:
Who is Participating?
 
woolmilkporcConnect With a Mentor Commented:
The first - elegant! - solution needs just a tiny correction:

f=${f//\//%2f}
echo $f
0
 
unknown_routineConnect With a Mentor Commented:
$ bar=${f////%2f}


$ echo ${bar}
0
 
Gerwin Jansen, EE MVEConnect With a Mentor Topic 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
All Courses

From novice to tech pro — start learning today.