I have a bash dialog form that generates four variables. Each individual variable - if not empty - will lead to a sed command execution on the same file.
Bash Dialog Script that generates four variables var1, var2, var3, var4
#!/usr/bin/env bash
response=$(dialog \
--title "ini configure" \
--form "Configure php.ini" \
15 50 0 \
"Execution Time:" 1 1 "$exe_time" 1 10 20 0 \
"Memory Limit:" 2 1 "$mem_limit" 2 10 20 0 \
"Max File Size:" 3 1 "$max_file" 3 10 20 0 \
"Max Post Size:" 4 1 "$max_post" 4 10 20 0 \
3>&1 1>&2 2>&3 3>&-)
responsearray=($response)
var1=${responsearray[0]}
var2=${responsearray[1]}
var3=${responsearray[2]}
var4=${responsearray[3]}
How to combine these four conditional sed commands?
if [[ -n "$var1" ]]; then
sed -i 's/^;*\max_execution_time = .*/max_execution_time = "${var1}"/' /user/php8.0-fpm/php.ini
if [[ -n "$var2" ]]; then
sed -i 's/^;*\memory_limit = .*/memory_limit = "${var2}"/' /user/php8.0-fpm/php.ini
if [[ -n "$var3" ]]; then
sed -i 's/^;*\max_file_size = .*/max_file_size = "${var3}"/' /user/php8.0-fpm/php.ini
if [[ -n "$var4" ]]; then
sed -i 's/^;*\max_post_size = .*/max_post_size = "${var4}"/' /user/php8.0-fpm/php.ini
I know I can combine multiple sed commands with a semicolon, but it is the conditional that's creating the issue.
OS: Ubuntu 20.04 Headless