Shell Uri Encoding


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Uri Encoding
# 1  
Old 03-25-2009
Shell Uri Encoding

It really to make for Russian?

from "тест" to "%D1%82%D0%B5%D1%81%D1%82"
# 2  
Old 03-25-2009
Quote:
Originally Posted by Trump
It really to make for Russian?

from "тест" to "%D1%82%D0%B5%D1%81%D1%82"

This function works in bash:

Code:
#@ uri_escape - convert STRING to hex-encoded string 
#@              and assign to optional VAR or _URI_ESCAPE
#@ Author: Chris F.A. Johnson, 2009-03-25
##
uri_escape() #@ USAGE: uri_escape STRING [VAR]
{
  local string x
  string=$1
  var=${2:-_URI_ESCAPE}

  while [ -n "$string" ] ## loop until $string is empty 
  do
     case $string in

       ## If alphanumeric or underscore, add it unchanged
       [_a-zA-Z0-9]* ) printf -v x "%s%c" "$x" "$string" ;;

       ## ...otherwise convert first character to hexadecimal
       *) printf -v x "%s%%%X" "$x" "'$string" ;;

     esac
     string=${string#?} ## remove first character from string
  done
  eval "$var=\$x"
}

uri_escape "тест" encoded

printf "%s\n" "$encoded"


Last edited by cfajohnson; 03-25-2009 at 10:49 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Solaris

View file encoding then change encoding.

Hi all!! I´m using command file -i myfile.xml to validate XML file encoding, but it is just saying regular file . I´m expecting / looking an output as UTF8 or ANSI / ASCII Is there command to display the files encoding? Thank you! (2 Replies)
Discussion started by: mrreds
2 Replies

2. Web Development

Apache website uri access

Hi i would like to grant access specific to one uri and rest of them should be denied. as follows: http://websitename/example user should be able to access htttp://websitename/other user should be denied (1 Reply)
Discussion started by: raghur77
1 Replies

3. Web Development

Iplanet webserver retaining the URI query string data.

Current Situation: 1. Visit: https://xyz.com/2015/september?trackingparam=1234 2. The URL is missing the trailing / after the “september” directory 3. The URL is redirected and rewritten to: https://xyz.com/2015/september/ , dropping the query string data. Note:... (0 Replies)
Discussion started by: raghur77
0 Replies

4. Shell Programming and Scripting

How to find the file encoding and updating the file encoding?

Hi, I am beginner to Unix. My requirement is to validate the encoding used in the incoming file(csv,txt).If it is encoded with UTF-8 format,then the file should remain as such otherwise i need to chnage the encoding to UTF-8. Please advice me how to proceed on this. (7 Replies)
Discussion started by: cnraja
7 Replies

5. UNIX for Advanced & Expert Users

Proxy must be specified as absolute URI

I encounter frequently a problem when installing Perl modules as follows: perl -MCPAN -e 'install Family::Module' The error message is: Proxy must be specified as absolute URI; ' ' is not at /usr/local/lib/perl5/5.8.8/CPAN.pm line 2357 even though I am not behind a proxy. Forcing to install the... (4 Replies)
Discussion started by: figaro
4 Replies

6. Shell Programming and Scripting

In PHP replacing text between TAGS & URI information in Title Tag

Hi, what I am trying to do in PHP, is to replace the Title. I need some of the URL information inside aswell depending on the domain. The title is always different so I need to store it in a variable, put the url info like described below in front of it. Here is an example how it should... (0 Replies)
Discussion started by: lowmaster
0 Replies

7. Debian

URI Devices issue

Hi gurus, I would like to migrate our windows print server to a debian linux but im newbie and i dont understand. when i try to add printer into Cups im going to localhost:631 and adding printers but i see this URI devices and i dont know how to deal with them? my test scenario is like this: A... (0 Replies)
Discussion started by: saveka
0 Replies

8. UNIX for Dummies Questions & Answers

encoding

Hi, I'm using putty and when I try to write ü it writes | (or when I try to write é , it writes i) I tried to change settings/translation of putty but with no success I have KSH # locale LANG= LC_CTYPE="C" LC_NUMERIC="C" LC_TIME="C" LC_COLLATE="C" LC_MONETARY="C" LC_MESSAGES="C"... (3 Replies)
Discussion started by: palmer18
3 Replies
Login or Register to Ask a Question