1

I have a function that returns a numeric value to indicate an error.

gimme_five() {
    return 5
}

Can I use this function as a number in an assignment?

That is, I would like to do something like the following

(( COUNT+=gimme_five ))

is this possible or must they always be separate statements, a la:

gimme_five
(( COUNT+=$? ))
Toby
  • 9,696
  • 16
  • 68
  • 132
  • The Q set as duplicate, does not have answers about using numerical return values directly, but instead about using general values *indirectly*. Here I am specifically asking if it is possible to use *numerical* values *directly*, or not. – Toby Oct 27 '21 at 20:38
  • 1
    A bash function does not have a return value. IMHO, the name _function_ for this construct is inappropriate; it should be called _procedure_ or _subroutine_ or something like that. When you do a `return 5`, it just sets the status code to 5 and returns to the caller. – user1934428 Oct 28 '21 at 06:55
  • 1
    `gimme_five() { echo 5; }; ((count += $(gimme_five)))` – Andrej Podzimek Oct 28 '21 at 15:54

0 Answers0