config_loader.sh

Shellマスター

Explorer

C40
C++40
C#40
Dart40
Go40
Java40
JavaScript40
Kotlin40
Objective-C40
Perl40
PHP40
Python40
R40
Ruby40
Rust40
Shell
初級10
中級10
上級10
エキスパート5
マスター5
parallel_batch.sh
trap_cleanup.sh
json_parser.sh
config_loader.sh
retry_wrapper.sh
Swift40
TypeScript40
config_loader.sh
Click to focus
1
2
3
4
5
6
7
8
9
10
11
12
load_config() {
   local -r config_file="${1:-config.env}"
   declare -gA CONFIG
   while IFS="=" read -r key value; do
       [[ -z "$key" || "$key" =~ ^# ]] && continue
       key="${key%%[[:space:]]}"
       value="${value#[[:space:]]}"
       CONFIG["$key"]="${value//\"/}"
   done < "$config_file"
   export "${!CONFIG[@]}"
}
load_config && echo "DB: ${CONFIG[DB_HOST]}:${CONFIG[DB_PORT]}"
0WPM0%0:000/394(0%)|Ln 1, Col 1
UTF-8Shell

関連する練習問題