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"
}