Created
June 2, 2012 14:17
-
-
Save pirogoeth/2858595 to your computer and use it in GitHub Desktop.
string processor and array tool for the upstream building feature im about to add to my compile.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function checkIfElementIsBlank () { | |
test ! -z ${1} | |
} | |
# quick awk lesson | |
# ============================================================================================ | |
# when using awk as a splitter, you will do awk '{print $#};', where # is the index number | |
# 0: entire string AFTER any proceeding formatting | |
# 1: first element in the string | |
# 2: second element in the string | |
# ... so on and so forth. | |
# ============================================================================================ | |
function getKey () { | |
echo ${1//','/ } | awk '{print $1};' | |
} | |
function getValue () { | |
echo ${1//','/ } | awk '{print $2};' | |
} | |
s=" | |
OpenAuth,/home/pirogoeth/OpenAuth; | |
OpenEconomy,/home/pirogoeth/OpenEconomy;" | |
s=${s//$'\n'/} | |
s=${s//";"/ } | |
array=( ${s} ) | |
for (( i=0; $i<${#array[@]}; i++ )) | |
do | |
checkIfElementIsBlank ${array[$i]} | |
echo "BLANK: $?" | |
echo "KEY: $(getKey ${array[$i]}), VALUE: $(getValue ${array[$i]})" | |
echo "Exporting.." | |
export "$(getKey ${array[$i]})"="$(getValue ${array[$i]})" | |
done | |
upstream=( "OpenAuth" "OpenEconomy" ) | |
for (( i=0; $i<${#upstream[@]}; i++ )) | |
do | |
echo ${!upstream[$i]} | |
done | |
# yay for indirect references! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment