开发者

Custom Config File Parsing in Bash

I'm creating a bash script for screen management and want 开发者_如何学Goto pull variables from a config file formatted like so:

[s=sample1]
FOLDER=folder/right/here
COMMAND=python script.py

[i=irssi]
COMMAND=irssi
BOOT

"FOLDER", "COMMAND", and "BOOT" would be optional. "[x=y]" would be required, where "x" is a single lowercase letter.

I'd like for this sample to be parsed into something like:

NAME[0]="sample1"
SHORT[0]="s"
FOLDER[0]="folder/right/here"
COMMAND[0]="python script.py"

NAME[1]="irssi"
SHORT[1]="i"
BOOT[1]="1"


If you really need to parse ini-styled config files in bash, have a look at this link. Else, as others have pointed out, just place the variables in a file and source it...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜