Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 19fb48e

Browse files
author
egberts
committed
Polish the example code
1 parent 474d6ac commit 19fb48e

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

‎README.md‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,37 @@ Features:
2929

3030
Demo
3131
====
32-
A nice bash script can be:
32+
A nice bash script can be either my `example-usage.sh` script or below:
3333

3434
```bash
3535
source bash-ini-parser.sh
36-
my_ini="$(cat "/etc/systemd/systemd.conf" | ini_file_read
36+
raw_data="$(cat "/etc/systemd/systemd.conf" | ini_file_read
3737
ini_kv_get "Default" "DNS"
38+
# outputs the keyvalue
39+
```
40+
41+
Or with `example-usage.sh`, this script will try to read systemd config file and determine which Display Manager that you are using:
42+
43+
```console
44+
$ bash example-usage.sh
45+
File : /etc/systemd/system/display-manager.service
46+
Keyword : ExecStart
47+
Keyvalue: /usr/bin/sddm # <--- your section/keyword/keyvalue answer
48+
49+
Came from all that below:
50+
"[Unit]Description=Simple Desktop Display Manager
51+
[Unit]Documentation=man:sddm(1) man:sddm.conf(5)
52+
[Unit]Conflicts=getty@tty1.service getty@tty7.service
53+
[Unit]After=getty@tty1.service getty@tty7.service
54+
[Unit]After=systemd-user-sessions.service systemd-logind.service
55+
[Unit]After=haveged.service
56+
[Service]ExecStart=/usr/bin/sddm
57+
[Service]Restart=always
58+
[Service]RestartSec=1s
59+
[Service]EnvironmentFile=-/etc/default/locale
60+
[Install]Alias=display-manager.service"
61+
62+
Done.
3863
```
3964
4065
Unit Test

‎bash-ini-parser.sh‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ ini_kw_get()
202202
#
203203
#
204204
# into BASH, for now, do simple removal of inline comment
205-
kv="$(echo "$kv" | sed "/^\s*;/d;s/\s*;[^\"']*$//")"
206-
# echo "kv2: $kv"
207-
kv="$(echo "$kv" | sed "/^\s*#/d;s/\s*#[^\"']*$//")"
208-
# echo "kv4: $kv"
209-
kv="$(echo "$kv" | sed "/^\s*\/\//d;s/\s*\/\/[^\"']*$//")"
205+
# kv="$(echo "$kv" | sed "/^\s*;/d;s/\s*;[^\"']*$//")"
206+
# # echo "kv2: $kv"
207+
# kv="$(echo "$kv" | sed "/^\s*#/d;s/\s*#[^\"']*$//")"
208+
# # echo "kv4: $kv"
209+
# kv="$(echo "$kv" | sed "/^\s*\/\//d;s/\s*\/\/[^\"']*$//")"
210210
# echo "kv5: $kv"
211211

212212
# remove surrounding whitespaces

‎example-usage.sh‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@
33
# Title: Demo of bash-ini-parser.sh
44
#
55

6+
ini_filespec="/etc/systemd/system/display-manager.service"
7+
section="Service"
8+
keyword="ExecStart"
9+
610
source bash-ini-parser.sh
711

8-
my_raw="$(cat /etc/systemd/system/display-manager.service)"
12+
raw_data="$(cat $ini_filespec)"
913

10-
my_ini="$(ini_file_read "$my_ini")"
14+
ini_settings="$(ini_file_read "$raw_data")"
1115

12-
ini_kw_get "$my_ini" "Service" "ExecStart"
16+
keyvalue="$(ini_kw_get "$ini_settings" "$section" "$keyword")"
1317

18+
echo "File : $ini_filespec"
19+
echo "Keyword : $keyword"
20+
echo "Keyvalue: $keyvalue # <--- your section/keyword/keyvalue answer"
21+
echo
22+
echo "Came from all that below:"
23+
echo "\"$ini_settings\""
24+
echo
25+
echo "Done."

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /