Search code examples
bashfunctionarithmetic-expressions

Can a function be used in $(( func arg ? str1 : str2 ))?


I'd like to use a statement like this:

var=$(( func arg ? str1 : str2 ))

but bash gives this syntax error message:

syntax error in expression (error token is "arg")

I've played with various forms but I can't figure out how to make it accept a function with argument. Any ideas?


Solution

  • I think the correct answer is that there is no way to use the statement I asked about. The problem is that this conditional operator can only evaluate to an integer and not a string as I wanted to do.

    jm666 answered the question in a comment to Steve's answer so I gave him an up vote.