#################################################### # KSH Function: read_config # Author : Rainer Raab ([email protected]) # Date : 11/28/2000 #################################################### # Description : Reads a configuration file and # exports variables to the shell. The configuration # file must be in text. If the first character in a # line contains a "[", "#" or the line is empty, the # entire line is ignored. If a configuration file # contains the special EMAIL_LIST variable, then # that variable must be a space separated list of # e-mail recipients. #################################################### # Usage: # CONFIG_FILE=/path_to_file/config_file # # Configuration File Format: # # [Section] # VARIABLE=value # # Configuration File Example: # [Delays] # # Delays are specified in seconds # DELAY_1=60 # DELAY_2=300 # # [Log files] # OUT_LOG=/var/adm/test_out.log # ERR_LOG=/var/adm/test_err.log #################################################### function read_config { while read LINE; do COLUMN1=$(printf "$LINE\n"|cut -c1,1) if [[ $COLUMN1 != "[" && $COLUMN1 != "#" && $COLUMN1 != "" ]]; then LABEL=$(printf "$LINE\n"|awk -F= '{ print $1 }') if [[ $LABEL = "EMAIL_LIST" ]]; then EMAIL_LIST=$(printf "$LINE\n"|awk -F= '{ print $2 }') else export $LINE fi fi done < $CONFIG_FILE }
Creating Global Functions with the Korn Shell
Related Reading
More Insights
INFO-LINK
To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy. | |