Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
Quack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
commul
Zeit.shift
Quack
Commits
0d6b4c22
Commit
0d6b4c22
authored
11 years ago
by
Toke Eskildsen
Browse files
Options
Downloads
Patches
Plain Diff
fixes #8 (newlines in all replacements)
parent
db2ffced
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
quack.sh
+9
-2
9 additions, 2 deletions
quack.sh
with
9 additions
and
2 deletions
quack.sh
+
9
−
2
View file @
0d6b4c22
...
@@ -200,7 +200,14 @@ function template () {
...
@@ -200,7 +200,14 @@ function template () {
# We need to escape \, &, / and newline in replacement to avoid sed problems
# We need to escape \, &, / and newline in replacement to avoid sed problems
# http://stackoverflow.com/questions/407523/escape-a-string-for-sed-search-pattern
# http://stackoverflow.com/questions/407523/escape-a-string-for-sed-search-pattern
# http://stackoverflow.com/questions/1251999/sed-how-can-i-replace-a-newline-n
# http://stackoverflow.com/questions/1251999/sed-how-can-i-replace-a-newline-n
(
echo
-n
"s/
\$
{
$PATTERN
}/"
;
echo
-n
"
$REPLACEMENT
"
|
sed
-e
's/[\\/&]/\\&/g'
|
awk
1
ORS
=
"
\\\\
&br;"
;
echo
"/g"
)
|
sed
-f
-
-i
$TEMPLATE
if
[
"
$REPLACEMENT
"
==
"
`
echo
-n
\"
$REPLACEMENT
\"
|
tr
'\\n'
'*'
`
"
]
;
then
# No newlines, especially no trailing ones!
(
echo
-n
"s/
\$
{
$PATTERN
}/"
;
echo
-n
"
$REPLACEMENT
"
|
sed
-e
's/[\\/&]/\\&/g'
|
sed
':a;N;$!ba;s/\n/\\\&bt;/g'
;
echo
"/g"
)
|
sed
-f
-
-i
$TEMPLATE
else
# The awk-version always adds a trailing newline, even when the input has none
(
echo
-n
"s/
\$
{
$PATTERN
}/"
;
echo
-n
"
$REPLACEMENT
"
|
sed
-e
's/[\\/&]/\\&/g'
|
awk
1
ORS
=
"
\\\\
&br;"
;
echo
"/g"
)
|
sed
-f
-
-i
$TEMPLATE
fi
# Insert into template, then unescape newlines
# Insert into template, then unescape newlines
sed
's/\&br;/\n/g'
-i
$TEMPLATE
sed
's/\&br;/\n/g'
-i
$TEMPLATE
}
}
...
@@ -494,7 +501,7 @@ function resolveAlternatives() {
...
@@ -494,7 +501,7 @@ function resolveAlternatives() {
local
ID
=
`
echo
$IMAGE
|
grep
-o
"[0-9][0-9][0-9][0-9]-.*"
`
local
ID
=
`
echo
$IMAGE
|
grep
-o
"[0-9][0-9][0-9][0-9]-.*"
`
if
[
"."
==
".
$ID
"
]
;
then
if
[
"."
==
".
$ID
"
]
;
then
echo
" Unable to extract ID for
\"
$IMAGE
\"
"
echo
" Unable to extract ID for
\"
$IMAGE
\"
. No alternatives lookup
"
return
return
fi
fi
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment