Skip to content

Instantly share code, notes, and snippets.

@odellt
Created November 8, 2019 13:05
Show Gist options
  • Save odellt/819347013d5dca536abd80d68606a610 to your computer and use it in GitHub Desktop.
Save odellt/819347013d5dca536abd80d68606a610 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Script to demonstrate capturing the exit status of a sub shell command while assigning the output to a local variable
test() {
local inline_declaration_and_definition=$(exit 3)
echo $? # output: 0
local separate_declaration_and_definition
separate_declaration_and_definition=$(exit 3)
echo $? # output: 3
}
test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment