Для первого:
# run sed, capture any output
var1="$(sed -i "/connection.username/c connection.username=$name" $search)"
Для последнего:
# run sed, discard all output but keep exit status
sed -i "/connection.username/c connection.username=$name" $search >/dev/null 2>&1
Тем не менее, valid() ... странно, мягко говоря. Я бы записал его как
# valid label [status]
# check status ($? if not provided) and log success/failure
function valid {
if [[ ${2-$?} == 0 ]]; then
echo "$1 : status : OK"
else
echo "$1 : status : ERROR"
fi
}
На самом деле, я бы сделал это несколько иначе, чем в начале:
# log label command [arguments...]
# run command, output success/failure to stderr. If label is empty, use the
# command name: 'log "" echo hi' uses 'echo' as the label.
# log entries look like
# label1 : status : OK
# label2 : status : ERROR
# Error output from foo:
# Baz is broken; fix and try again.
log() {
# save off label
local label="${1:-$2}"
shift # this removes $1 and shifts $2... to $1... so "$@" works later
# run command, capture output
# $(command) runs 'command' and substitutes its output
# "$@" preserves quoting; $* would turn argument "foo bar" into two
# arguments foo bar
err="$("$@")"
if [[ $? == 0 ]]; then
status=OK
else
status=ERROR
fi
echo "$label : status : $status" >&2 # standard error
if [[ $status == ERROR ]]; then
# log output from command, indented for clarity
echo "Error output from $2:"
echo "$err" | sed 's/^/ /' >&2
fi
}
save() {
# this sed command is pedantically correct; if GNU sed lets you
# do single-line 'c' commands as in the original, then go for it.
# The backslash-return after the label argument is just for clarity;
# 'log "foo" bar' works just as well.
log "adding database ip" \
sed -i "/:@/c\\
connection.url=jdbc:oracle:thin:@$ip:1521:$dataBase\\
." "$search"
# using the original (GNU?) sed syntax
log "adding database SID" \
sed -i "/connection.username/c connection.username=$name" "$search"
}
save
Я бы также включил метку времени и идентификатор программы и т. Д. в реальной программе.
Вероятно, вам следует изучить Руководство по разработке сценариев Advanced Bash, чтобы узнать больше о написании сценариев оболочки. Главы оболочки оболочки UNIX не распространяют расширения bash на исходную оболочку Bourne, но по-прежнему полезны для изучения «zen» сценариев оболочки.
Вы также можете попробовать RationalPlan Single. Это не открытый исходный код, но он бесплатный для пользователей Linux.
RationalPlan хорош, и единственная версия бесплатна для Linux. Gantter также не упоминается здесь и полностью интегрирован с Google Диском. Если вы прокрутите вниз эту статью, есть несколько хороших альтернатив с открытым исходным кодом, которые работают как на Linux, так и на Mac: Источник: https://machow2.com/best-alternatives-microsoft-project-mac/