ngs-lang / ngs

Next Generation Shell (NGS)
https://ngs-lang.org/
GNU General Public License v3.0
1.39k stars 43 forks source link

Integrate TOML parser and generator #510

Open organom opened 2 years ago

organom commented 2 years ago

Similar to https://github.com/ngs-lang/ngs/issues/217

organom commented 2 years ago

Example of bash to extract a field:

#!/usr/bin/env bash

FILE=$1
KEY=$2

while read line;do
  if [[ $line =~ ^\[([^\ ]+)\ *\]$ ]];then
    section="${BASH_REMATCH[1]}"
    continue
  fi

  if [[ $line =~ ^([^=\ ]*)\ *=\ *\"(.*)\"\ *$ ]];then
    k="${section}.${BASH_REMATCH[1]}"
    if [[ $k == $KEY ]];then
      echo "${BASH_REMATCH[2]}"
      exit 0
    fi
  fi

done < "$FILE"
exit 1