I have a bash script that has as a variable a urlencoded string, that I want to be decoded. I know this can be done with bash, but I thought I might as well just call a the PHP function urldecode() and be done with it.
I would have preferred to run the php function in the bash code, but I opted to write a very simple script
<?php
echo urldecode($argv);
?>
and call this script in the bash script
#!/bin/bash
...#$MYURL is an encoded url
...
$MYURL="php myurldecodescript.php -- $MYURL"
Unfortunately this doesn’t work.
How is it best to do this?
You can do this, using PHP, without having to create the
myurldecodescript.phpfile. If you supply a-roption to PHP, it will run code that you specify in the command line. So you can do this: