0

What does this code do?

set +e
( set -e
 "$@"
)
ret=$?
set -e

I don't understand code in parentheses?

Mihir Luthra
  • 6,059
  • 3
  • 14
  • 39
Dims
  • 47,675
  • 117
  • 331
  • 600
  • I think this is more a duplicate of https://unix.stackexchange.com/questions/26063/how-are-parentheses-interpreted-at-the-command-line – Chris Maes Aug 12 '19 at 13:14
  • 1
    It runs the commands in a subshell. It's a way to avoid having the `set -e` leak outside the subshell. – tripleee Aug 12 '19 at 13:15
  • @tripleee and what does it do here? prints `$@`? runs `$@`? – Dims Aug 13 '19 at 08:14
  • `"$@"` is the list of arguments to the current script or function. The double quotes are significant and important (`$@` without quotes is basically always a bug). – tripleee Aug 13 '19 at 08:46
  • @tripleee ya, I know that `$@` is a list of arguments, but what does it do in nested parentheses? – Dims Aug 13 '19 at 09:36
  • Exactly the same thing. It contains the arguments of the function or script these nested parentheses are in. Maybe it gets called something like `noerror echo "hello there"` where you might have the function definition `noerror () { ( set -e; "$@" ); }` and it thus end up executing `(set -e; echo "hello there" )` – tripleee Aug 13 '19 at 09:47

0 Answers0