Question: I did a script with an `if` that takes several hundred lines because it lists all the possibilities, I would like to know if it is possible to reduce its size to only a few lines because I find myself lost in all these lines. Here is an example of the code: 

```
if [ "$player_position" = 1 ]; then
  echo "Player is on the tile 1"
elif [ "$player_position" = 2 ]; then
  echo "Player is on the tile 2"
elif [ "$player_position" = 3 ]; then
  echo "Player is on the tile 3"
fi

```

And so on. I want to get rid all the `elif` but keep all the possibilities 

PS : Each tile has a name that is in a variable like "tile\_1\_name" that number also has to change

Answer: 
If you are using a recent version of bash (4.4 I believe), you can use [a "nameref"](https://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameters)

```
# first check the bounds of the position
if (( 1 <= player_position && player_position <= max_upper_position )); then
    declare -n tile="tile_${player_position}_name"
    echo "Player is on the tile ${tile:-with no name}"
else
    echo "Invalid player position: $player_position"
fi

```

However, you should stop using "dynamic" variable names like "tile\_1\_name". Instead use an array:

```
tile_names[4]="Fourth tile"
...
echo "Player is on the tile ${tile_names[$player_position]:-with no name}"

```
```
if  [ "$player_position" -ge 1 -a "$player_position" -le 3 ]; then
  echo "Player is on the tile $player_position"
fi

```

Explanation:

* `-ge`: greater than or equal
* `-le`: less than or equal
* `-a`: logical AND