Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
a25b2af6
Commit
a25b2af6
authored
Jul 29, 2017
by
Ondrej Simek
Browse files
Get rid of _find_num
parent
31b67ab9
Changes
1
Hide whitespace changes
Inline
Side-by-side
dnsapi/dns_he.sh
View file @
a25b2af6
...
...
@@ -149,9 +149,18 @@ _find_zone() {
fi
_debug
"Looking for zone
\"
${
_attempted_zone
}
\"
"
_line_num
=
$(
echo
"
$_zone_names
"
| _find_linenum
"
$_attempted_zone
"
)
if
[
-n
"
$_line_num
"
]
;
then
_zone_id
=
$(
echo
"
$_zone_ids
"
|
sed
"
${
_line_num
}
q;d"
)
# Take care of "." and only match whole lines. Note that grep -F
# cannot be used because there's no way to make it match whole
# lines.
regex
=
"^
$(
echo
"
$_attempted_zone
"
|
sed
's/\./\\./g'
)
$"
line_num
=
$(
echo
"
$_zone_names
"
\
|
grep
-n
"
$regex
"
\
|
cut
-d
:
-f
1
)
if
[
-n
"
$line_num
"
]
;
then
_zone_id
=
$(
echo
"
$_zone_ids
"
|
sed
"
${
line_num
}
q;d"
)
_debug
"Found relevant zone
\"
$_attempted_zone
\"
with id
\"
$_zone_id
\"
- will be used for domain
\"
$_domain
\"
."
return
0
fi
...
...
@@ -160,30 +169,4 @@ _find_zone() {
_strip_counter
=
$(
_math
"
$_strip_counter
"
+ 1
)
done
}
#-- _find_linenum()-----------------------------------------------------
# Returns line number of line (supplied as an argument) in STDIN.
#
# Example:
#
# printf "a\nb\nc" | _find_linenum "b"
#
# This will:
# - print out 2 because that's the line number of "b"
# - return code 0 because it was found
_find_linenum
()
{
_current_line_num
=
0
while
read
-r
line
;
do
_current_line_num
=
$(
_math
"
$_current_line_num
"
+ 1
)
if
[
"
$line
"
=
"
$1
"
]
;
then
# Found! Let's echo the line number and quit
echo
"
$_current_line_num
"
return
0
fi
done
# Not found
return
1
}
# vim: et:ts=2:sw=2:
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment