Skip to content

Instantly share code, notes, and snippets.

View maxpatternman's full-sized avatar

Max Patternman maxpatternman

View GitHub Profile
@rcknr
rcknr / urlencode.sh
Created January 8, 2013 21:39
Simplistic URL encoding for Busybox shell.
#!/bin/sh
echo "$@" | awk -v ORS="" '{ gsub(/./,"&\n") ; print }' | while read l;
do
case "$l" in
[-_.~a-zA-Z0-9] ) echo -n ${l} ;;
"" ) echo -n %20 ;;
* ) printf '%%%02X' "'$l"
esac
done
@cosimo
cosimo / parse-options.sh
Created September 21, 2012 09:31
Example of how to parse options with bash/getopt
#!/bin/bash
#
# Example of how to parse short/long options with 'getopt'
#
OPTS=`getopt -o vhns: --long verbose,dry-run,help,stack-size: -n 'parse-options' -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
echo "$OPTS"