samedi 7 septembre 2019

why in an if statement then has to be in the next line?

if is followed by then in bash but I don't understand why then cannot be used in the same line like if [...] then it has to be used in the next line. Does that remove some ambiguity from the code? or bash is designed like that? what is the underlying reason for it?

I tried to write if and then in the same line but it gave the error below:

./test: line 6: syntax error near unexpected token \`fi' ./test: line 6: \`fi'

the code is:

#!/bin/bash if [ $1 -gt 0 ] then echo "$1 is positive" fi

Aucun commentaire:

Enregistrer un commentaire