#!/bin/bash

# convert text to uri (percentage) encoding
# txt2uri text_string_quoted
# returns URI string


  string=$1
  while [ -n "$string" ]; do
    tail=${string#?}
    head=${string%$tail}
    case $head in
      [-._~0-9A-Za-z]) printf %c "$head";;
      *) printf %%%02x "'$head"
    esac
    string=$tail
  done
