pvincent
9 months ago
7 changed files with 33 additions and 44 deletions
-
0appended
-
32lib/functions.sh
-
17tools/append_or_replace
-
8tools/erase_lines
-
10tools/genpasswd
-
2tools/semver_git_tag
-
8uninstall.sh
@ -1,22 +1,19 @@ |
|||
#!/bin/bash |
|||
|
|||
usage() { |
|||
echo "Usage: $(basename "$0") <REGEX> <STRING> <FILE>" |
|||
function usage { |
|||
builtin echo "Usage: $(basename "$0") <REGEX> <STRING> <FILE>" |
|||
} |
|||
|
|||
if [[ $# -ne 3 ]]; then |
|||
usage |
|||
exit 2 |
|||
fi |
|||
[[ $# -ne 3 ]] && usage && exit 2 |
|||
|
|||
REGEX=$1 |
|||
STRING=$2 |
|||
FILE=$3 |
|||
|
|||
if ! grep -Eq "$REGEX" "$FILE"; then |
|||
printf "$STRING\n" >>$FILE |
|||
echo appended |
|||
printf "%s\n" "$STRING" >>"$FILE" |
|||
echo 'appended' |
|||
else |
|||
sed -Ei "s|$REGEX|$STRING|g" $FILE |
|||
echo replaced |
|||
sed -Ei "s|$REGEX|$STRING|g" "$FILE" |
|||
echo 'replaced' |
|||
fi |
Write
Preview
Loading…
Cancel
Save
Reference in new issue