Bash here. I want to write a script that declares several variables, assigns them different values based on a conditional, and then uses them later on (whatever they were conditionally assigned to):
#!/usr/bin/bash
$fizz
$buzz
$foo
if [ -z "$1" ]
then
fizz = "Jane Smith"
buzz = true
foo = 44
else
fizz = "John Smith"
buzz = false
foo = 31
fi
# now do stuff with fizz, buzz and foobar regardless of what their values are
When I run this (bash myscript.sh) I get errors. Can anyone spot if I have a syntax error anywhere? Thanks in advance!
=.$foois not a declaration, if it had a value it would be executed as a command. The if statement logic is fine, assuming you want Jane if the first arg is empty, and John if it isn't.