1

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
1
  • 1
    This might be helpful. Commented Nov 7, 2016 at 19:17

1 Answer 1

3

The syntax is incorrect, but there is a parameter expansion operator to do what you want.

myval=${1:-$val}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.