Find the answer to your Linux question:
Results 1 to 3 of 3
Hi people. So I'm trying to write a Bash script that converts a string into URL Hex format (i.e. replaces quotation marks with %22, spaces with %20, etc.) So far ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    May 2004
    Location
    Boston, MA
    Posts
    246

    Quote replacing in Bash


    Hi people.

    So I'm trying to write a Bash script that converts a string into URL Hex format (i.e. replaces quotation marks with %22, spaces with %20, etc.) So far I've been able to make the spaces work with

    words=${words// /%20}

    But when I tried to replace the question marks with

    words=${words//\"/%22}, it just gave me the string without the quotations. This is probably because when I type in the string as "something something", it takes out the quotation marks, right? So let's say I want to be able to type

    $ bash my.script Convert "this stuff"

    and get out

    Convert%20%22this%20stuff%22

    Does anyone know how to do that?

  2. #2
    Linux Guru
    Join Date
    Mar 2003
    Location
    Wisconsin
    Posts
    1,907
    Have you tried single quotes?

    Jeremy
    Registered Linux user #346571
    "All The Dude ever wanted was his rug back" - The Dude

  3. #3
    Just Joined!
    Join Date
    May 2004
    Posts
    13
    You may need to escape the double quote.
    eg. \" otherwise it would be read as normal by the shell.

    I have a vague memory of either vi or vim being able to convert html to text and vice versa, it may also change urls from text to a url too. There may also be a tool that has already been created for this purpose.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •