lundi 7 novembre 2016

Conditional if opertor in bash

Set the value of myval to $1 if it is not empty. If it is empty, set value of myval to val. Is this syntax correct in bash?

#!/bin/bash

val=5
myval=""
if [ "$val" != "" ]; then
    myval=("$1" == "" ? $val : $1)
fi
echo $myval

Aucun commentaire:

Enregistrer un commentaire