Skip to content

Instantly share code, notes, and snippets.

@byteface
Created August 24, 2015 01:31
Show Gist options
  • Save byteface/54dfd290165d2cefe296 to your computer and use it in GitHub Desktop.
Save byteface/54dfd290165d2cefe296 to your computer and use it in GitHub Desktop.
some bash stuff
# LOGGING ------------------
# log to output file
log(){
message=$( echo `date +%T` - $1 )
echo $message >> 'json/'$LOGFILE
}
# create a log file
LOGFILE=$( echo `date +%F_%T`.log )
#touch 'json/'$LOGFILE
log 'LOG FILE CREATED - READY TO IMPORT DATA'
log '***************************************'
log ''
# utils ------------------
# json array from comma string
json_array() {
echo -n '['
while [ $# -gt 0 ]; do
x=${1//\\/\\\\}
echo -n \"${x//\"/\\\"}\"
[ $# -gt 1 ] && echo -n ','
shift
done
echo ']'
}
export -f json_array
#bash array from string
ar_string=$( echo $string | sed 's/ //g' )
# printf '%s\n' "${ar_string[@]}"
# echo ${#ar_string[@]}
# turn array string into a bash array
IFS=',' read -a my_array <<< "ar_string"
for each in "${my_array[@]}"
do
#slice - change number for different slash
local car="$(echo "$path" | cut -d '/' -f 3)"
echo "car:"$car
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment