This repository has been archived on 2022-02-20. You can view files and clone it, but cannot push or open issues/pull-requests.
bash-shell-base/function/comment

15 lines
368 B
Plaintext
Raw Normal View History

#!/bin/bash
function comment_line() {
local regex="${1:?}"
local file="${2:?}"
local comment_mark="${3:-#}"
sed -ri "s:^([ ]*)($regex):\\1$comment_mark\\2:" "$file"
}
function uncomment_line() {
local regex="${1:?}"
local file="${2:?}"
local comment_mark="${3:-#}"
sed -ri "s:^([ ]*)[$comment_mark]+[ ]?([ ]*$regex):\\1\\2:" "$file"
}