MIAOU-BASH is a collection of settings and helpers for leveraging BASH. Developer-friendly, it may be used as solo package with or without the miaou project.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
292 B

10 months ago
  1. #!/bin/bash
  2. usage() {
  3. echo "Usage: $(basename "$0") <REGEX> <STRING> <FILE>"
  4. }
  5. if [[ $# -ne 3 ]]; then
  6. usage
  7. exit 2
  8. fi
  9. REGEX=$1
  10. STRING=$2
  11. FILE=$3
  12. if ! grep -Eq "$REGEX" "$FILE"; then
  13. printf "$STRING\n" >>$FILE
  14. echo appended
  15. else
  16. sed -Ei "s|$REGEX|$STRING|g" $FILE
  17. echo replaced
  18. fi