in Education by
Tested for Bash 5.0.2 According to the GNU Bash Reference Manual, Bash performs the expansion [of a command substitution] by executing [the] command in a subshell environment According to The Open Group Base Specifications Issue 6: when a subshell is entered, traps that are not being ignored are set to the default actions. So when running the following script: function a { trap -p EXIT } trap "echo 'parent'" EXIT echo "$(a)" (a) trap - EXIT echo 'exiting' ... i would expect an output of: exiting ... but instead I get: trap -- 'echo '\''parent'\''' EXIT trap -- 'echo '\''parent'\''' EXIT exiting ... meaning that the function a - eventhough it is being run in a subshell - is seeing the the parent shell's trap commands (via trap -p) but not executing them. What is going on here? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You'll notice that the traps trigger exactly according to spec. It's just the output from trap that's unexpected. This is a feature in Bash 4.2 (release notes): b. Subshells begun to execute command substitutions or run shell functions or builtins in subshells do not reset trap strings until a new trap is specified. This allows $(trap) to display the caller's traps and the trap strings to persist until a new trap is set. Normally, people would take this for granted. Consider this totally unsurprising Bash exchange: bash$ trap trap -- 'foo' EXIT trap -- 'bar' SIGINT bash$ trap | grep EXIT trap -- 'foo' EXIT Now look at the result in other shells like Dash, Ksh or Zsh: dash$ trap trap -- 'foo' EXIT trap -- 'bar' INT dash$ trap | grep EXIT (no output) This is perhaps more correct, but I doubt many people would expect it.

Related questions

0 votes
    Tested for Bash 5.0.2 According to the GNU Bash Reference Manual, Bash performs the expansion [of a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    I have created different fragment and populated some menu based on the fragment. I was getting duplicate ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    This is my pretty simple C++/CMake .travis.yml env: global: # The next declaration is the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Which of the following is the port number for SNMP - Trap? (a) 160 (b) 161 (c) 162 (d) 163 I got ... bank, Cyber Security questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 4, 2021 in Education by JackTerrance
0 votes
    I am creating a maven project from scratch, first just learn how to use maven. The main project contains ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I am creating a maven project from scratch, first just learn how to use maven. The main project contains ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    So I have some code which copies files to 5 remote PCs on the network. I have a class which ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I want to make a button Go To Cart visible after adding a product into cart. But when page gets ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    I'm trying to overlay 2 ImageViews, one with the background and one with an animated (using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I'm trying to overlay 2 ImageViews, one with the background and one with an animated (using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    The notes which are not visible to the audience during the slideshow are called. Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
0 votes
    In which tab of normal voew,the text box is not visible . Select the correct answer from above options...
asked Dec 24, 2021 in Education by JackTerrance
...