Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. source Configuration.conf
  2.  
  3. echo $Name
  4. echo $Age
  5. echo $Address
  6.  
  7. source Configuration.conf
  8. while [ $1 ] // Here 1 is representing the first Key of the configuration file.
  9. do
  10. //My Logics
  11. done
  12.  
  13. configfile=./Configuration.conf
  14.  
  15. . "$configfile"
  16.  
  17. declare -A configlist
  18.  
  19. while IFS='=' read -r key val ; do
  20.  
  21. # skip empty / commented lines and obviously invalid input
  22. [[ $key =~ ^[[:space:]]*[_[:alpha:]] ]] || continue
  23.  
  24. # Stripping up to the last space in $key removes "export".
  25. # Using eval to approximate the shell's handling of lines like this:
  26. # var="some thing with spaces" # and a trailing comment.
  27. eval "configlist[${key##* }]=$val"
  28.  
  29. done < "$configfile"
  30.  
  31. # The keys are "${!configlist[@]}", the values are "${configlist[@]}"
  32. #
  33. #for key in "${!configlist[@]}" ; do
  34. # printf '"%s" = "%s"n' "$key" "${configlist[$key]}"
  35. #done
  36.  
  37. for value in "${configlist[@]}" ; do
  38. : your logic goes here
  39. done
  40.  
  41. keys=( $(grep -oP 'w+(?==)' conf.conf) )
  42. for (( i=0; i < ${#keys[@]}; i++ )); do
  43. printf "%dt%sn" $i "${keys[i]}"
  44. done
  45. echo
  46. source conf.conf
  47. for var in "${keys[@]}"; do
  48. printf "%st=> %sn" "$var" "${!var}"
  49. done
  50.  
  51. 0 Name
  52. 1 Age
  53. 2 Address
  54.  
  55. Name => name_value
  56. Age => age_value
  57. Address => addr_value
  58.  
  59. sed -n 's/export//p' conf.sh | while read expression ; do
  60. key=$(cut -d= -f1 <<< "$expression")
  61. value=$(cut -d= -f2 <<< "$expression")
  62.  
  63. # your logic comes here ...
  64. echo "$key -> $value"
  65. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement