Stack Overflow archive
2 scoreaccepted

bash if elif statement always prints first value

score
2
question views
202
license
CC BY-SA 3.0

You need to add whitespace to the conditions:

bash
#!/bin/bash
config="update_release"
if [ "$config" == "update" ]; then
   schema_list="main_schemas"
elif [ "$config" == "update_release" ] ; then
   schema_list="release_schemas"
elif [ "$config" == "update_maintenance" ]; then
   schema_list="maintenance_schemas"
fi
echo $schema_list

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.