Created
February 22, 2012 15:48
-
-
Save mkaito/1885631 to your computer and use it in GitHub Desktop.
Revisions
-
Kaito Michishige created this gist
Feb 22, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #!/usr/bin/env zsh # An example script that reads a colon separated rc file, given on argv # Line format expected: # option: value # Mind the colon and space separating option name from the value. # Adjust the parameter expansion as needed if you change the line format. # - read <var> will read a line at a time. # - Piping the file name into the while block reads the file into the read call. # - typeset -A <var> explicitly marks a hash for ZSH. # declare -A <var> is the same for bash. # - Fancypants parameter expansion gives us opts[option]=value. # - Quoting the value allows is to be any valid string, which generally means # that the value will be anything between the colon and the next newline character. if [[ -f $1 ]]; then typeset -A opts while read l; do opts[${l%%:*}]="${l##*: }" done < $1 fi echo "Number of found options: ${#opts[*]}" for k in ${(k)opts}; do echo "$k => ${opts[$k]}" done