This script works if I use bash on my Debian 11 (bullseye). But now I need to refactor it to use Debian's
sh
shell(/bin/dash
).
#!/bin/dash
var1=1
var2=2
var3=3
arr=($var1 $var2 $var3)
exist_var="${arr[*]:+ message}"
echo $exist_var
Now, I get a message if any variable is set:
tuy@debian$ bash sh_array.sh
message
And I get no message if a variable is not set:
tuy@debian$ bash sh_array.sh
$
###
I know dash does not support arrays. If any of the variables is defined, the script must print a message. If no variables are defined, this script must still work, but without printing a message.
Asked by tuytuy20
(115 rep)
Apr 9, 2023, 02:02 PM
Last activity: Apr 9, 2023, 03:37 PM
Last activity: Apr 9, 2023, 03:37 PM