[Webinar] Streamline your web hosting managementRegister Today

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

Passing blank spaces, |, % to my CGI in sh

Hi,
  When I pass blank spaces,%, |, etc
from my web page to my cgi it comes with
extra characters, do you know how to
avoid them?. I am using sh in UNIX (I can not
use Perl).

Thanks.
0
aacosta
Asked:
aacosta
  • 11
  • 7
1 Solution
 
ozoCommented:
What do you mean extra characters?
Do they show up as +, %25, %72, respectively?
Do you want to translate them back to space, %, | ?
Can you use awk?
0
 
aacostaAuthor Commented:
yes,
Thats is what I want.
In this moment, the script shows me + as blank spaces, %25, %72, etc.

I need to translate this kind of characters to "normal" characters and so on (I think there are more than three "special characters")

Yes, I can use awk.

Thanks!.
0
 
aacostaAuthor Commented:
Adjusted points to 216
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
aacostaAuthor Commented:
It is urgent!.
I can use awk and almost any command of the shell (sh).
I need to receive a form (four lines) correctly in my cgi script.

I have just adjusted the points to 516!!.


0
 
ozoCommented:
nawk 'BEGIN{FS="%";ORS=""}{print $1; for( i=2; i<=NF; i++ ){printf "%c",system("ksh \"exit $((16#" substr($i,0,2) "))\""); print substr($i,3); } print "\n"}'
0
 
aacostaAuthor Commented:
Hi,
 I tried to use the statement you gave me but it did not worked.
The string that comes from my web page is called USERNAME and contains the following (this is an example, of course it changes for any character):

USERNAME=ale+acosta+alamo&OLD_PASSWORD=123456&NEW_PASSWORD=abc&CONF_NEW_PASSWORD=abc

(this is the value I obtain from echo $USERNAME in my cgi).

I used $1 and $USERNAME in the command but did not work either.

Thanks.
0
 
ozoCommented:
echo $USERNAME | tr '+' ' ' | nawk 'BEGIN{FS="%";ORS=""}{print $1; for( i=2; i<=NF; i++ ){printf "%c%s",system("ksh exit $((16#" substr($i,0,2) "))"),substr($i,3); } print RS }'
0
 
ozoCommented:
echo $USERNAME | tr '+' ' ' | nawk 'BEGIN{FS="%";ORS=""}{print $1; for( i=2;i<=NF; i++ ){printf "%c%s",system("ksh \"exit $((16#" substr($i,0,2) "))\""),substr($i,3);} print RS }'
0
 
aacostaAuthor Commented:
It almost worked!. The blank spaces pass correctly, if I pass a variable with %, |, ?,;, etc there appear just white square (). Why?

Thanks again.

Ale,-
0
 
aacostaAuthor Commented:
Great! and thanks. I was trying the firts one.

Ale,-
0
 
aacostaAuthor Commented:
Thanks.
0
 
aacostaAuthor Commented:
Hi again, is there a way to substitude nawk by awk?, I tried to do it and did not work. In addition I tried gawk.

The problem is that I am now in a Linux box.

Sorry again.

Alejandro
0
 
ozoCommented:
it would be easiest if you could use Perl...
0
 
aacostaAuthor Commented:
Yes I know.
I would like to use perl but the code is already done in a shell script and now we want to adapt it to the web(sorry).
Can I substitude the nawk in your command with awk some way?. I tried to do it but did not work.

Thks!.-
0
 
ozoCommented:
shell scripts can call perl as easily as they can call awk or nawk.
It can still be done with awk, but it gets a bit messy:

awk 'BEGIN{FS="%";}{print "echo -n " $1; for( i=2;i<=NF; i++ ){print "echo $((16#" substr($i,0,2) ")) | awk \\{printf\\\"%c\\\",\\$1\\}"; print "echo -n " substr($i,3);} }' | ksh
0
 
aacostaAuthor Commented:
Hi, again.
I tried the command you told me and did not work.

In addition I tried:

echo $USERNAME|awk 'BEGIN{FS="%";}{print "echo -n " $1; for( i=2;i<=NF; i++ ){print "echo $((16#" substr($i,0,2) ")) | awk \\{printf\\\"%c\\\",\\$1\\}"; print "echo -n " substr($i,3);} }' | ksh

And did not work :-(

In addition I tried something like:

echo $USERNAME | tr '+' ' ' | awk 'BEGIN{FS="%";}{print "echo -n " $1; for( i=2;i<=NF; i++ ){print "echo $((16#" substr($i,0,2) ")) | awk \\{printf\\\"%c\\\",\\$1\\}"; print "echo -n " substr($i,3);} }' | ksh

And did not work neither.

Where do I have to use $USERNAME (the var from the web page) in your command (remember I am newbie).

If you like we can call perl from the shell script but I dont want to create a new file.

Sorry and thanks again.
0
 
ozoCommented:
I'd ask what you get from just
echo $USERNAME | tr '+' ' ' | awk 'BEGIN{FS="%";}{print "echo -n " $1; for(i=2;i<=NF; i++ ){print "echo $((16#" substr($i,0,2) ")) | awk \\{printf\\\"%c\\\",\\$1\\}"; print "echo -n " substr($i,3);} }'
without the | ksh
but if you can call perl from the shell script, it may be easier to just use
echo $USERNAME | perl -pe 'tr/+/ /;s/%(\w\w)/pack"H2",$1/ge'
0
 
aacostaAuthor Commented:
Hi, The first command did not work, my vars were empty.

The second one (with perl) worked perfectly!.

Really thanks again.

Alejandro Acosta A.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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