Demand
Sometimes in the shell script needs some execution, if placed in the program is not easy to unified management, and every time you modify the path to the script inside to change the trouble, so the unified path in the configuration file easy to manage.
Problem
How to read the corresponding Key-value is the main problem, mainly using the IFS separator, remember to use the best back up the original IFS, use the end remember to restore IFS, otherwise there will be unknown error
configuration file (format: "key = value")
1 [CSV] 2 splithome = 20151214_ql/split_home3 output = 20151214_ql/output
Read Code (determine if the configuration file exists----Backup IFS-----read and output desired results-------restore IFS)
1 #!/bin/bash2 3 #Config file4config="Config.ini"5 6 #judge whether Config.ini exists or not.7 if[!-F"$config"];then8Echo"The file of Config.ini not exist"9 Exit 0Ten fi One A #Save The old IFS -oldifs=$IFS - the #set the IFS which is used to split the Key-value -ifs=" = " - -split="Splithome" +output="Output" - +s="" Ao="" at - whileRead-r Name Value - Do - if[["$name"= * $split * ]]; Then -s=$value - elif[["$name"= * $output *]];then ino=$value - fi toDone <$config + - #Output The result the Echo $s * Echo $o $ Panax Notoginseng #Reset the IFS -ifs=$OLDIFS the~
Command line output results
1 20151214_ql/split_home2 20151214_ql/output
Shell script-Read configuration file