A bit of background A while ago I posted an article describing how one could parse complete URIs in Bash using the sed program. Since then, I have realized that there is a better way to do it, a much better way: via Bash built-in pattern matching! Here are some benefits of this improvement: It no longer executes external programs (i.e. sed) for pattern matching. This translates to higher speed
Continue readingTag: bash
Bash URI parser using SED
Warning! This version is now obsolete! Check out the new and improved version (using only Bash built-ins) here! Here is a command-line (bash) script that uses sed to split the segments of an URI into usable variables. It also validates the given URI since malformed strings produce the text “ERROR” which can be handled accordingly: # Assembling a sample URI (including an injection attack) uri_1=’http://user:pass@www.example.com:19741/dir1/dir2/file.php’ uri_2=’?param=some_value&array[0]=123¶m2=\`cat /etc/passwd\`’ uri_3=’#bottom-left’ uri=”$uri_1$uri_2$uri_3″ #
Continue reading