Skip to content

Commit dc79788

Browse files
committed
[type/__cron] Merge grep + awk
Running grep(1) when we already run awk(1) is superfluous. awk can do both tasks at the same time.
1 parent 16760b9 commit dc79788

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

  • type/__cron/explorer

type/__cron/explorer/entry

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh -e
22
#
3-
# 2022 Dennis Camera (dennis.camera at riiengineering.ch)
3+
# 2022,2025 Dennis Camera (dennis.camera at riiengineering.ch)
44
#
55
# This file is part of skonfig-base.
66
#
@@ -34,7 +34,15 @@ crontab_list() {
3434
}
3535

3636
grep_suffix() {
37-
awk -v suffix="$1" 'substr($0, length($0) - length(suffix) + 1) == suffix'
37+
awk -v suffix="$1" '
38+
# skip comment lines
39+
/^[[:blank:]]*#/ { next }
40+
41+
{
42+
if (substr($0, length($0) - length(suffix) + 1) == suffix) {
43+
print
44+
}
45+
}'
3846
}
3947

40-
crontab_list | grep -v '^[[:blank:]]*#' | grep_suffix " # ${name}"
48+
crontab_list | grep_suffix " # ${name}"

0 commit comments

Comments
 (0)