305 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
1
answer
60
views
The subshell's trap is caught by the main shell, but the -E option is not used
function set_trap_for_exception() {
function _on_error() {
echo "error start"
exit 1
}
trap '_on_error "$BASH_COMMAND" $LINENO' ERR
}
function is_hygon_cpu() {
...
4
votes
1
answer
122
views
How to populate global variable from function which is in a pipe?
I would like to have function change value of global variable, but it fails when the function is used in a pipe:
#!/bin/bash
declare GVAR="abc"
func1() {
read GVAR
echo>...
0
votes
4
answers
173
views
How to pass complex serialized variables from a (remote) subshell to the parent?
I would like to do equivalent of name referencing from a function run in a subshell, so that arbitrary variable (e.g. associative array) is then available in the parent.
Note on duplicates: I found ...
2
votes
2
answers
83
views
How to read piped output produced in background subshell
I'm creating a script where multiple outputs from background processes are captured through while-read loop. However, it only works if I capture output directly to while loop. Trimmed down version of ...
1
vote
1
answer
63
views
Console output from subshell ONLY on failure
I have complex multi-step 'init' operations which can be ignored when they work. Having the echoed commands and their output at the beginning of every operation swamps the output you care about.
I ...
2
votes
1
answer
151
views
Why is Bash errexit (`set -e`) not passed into command substitution `$()` subshell, but is passed into `()`-subshell
I'm struggling with why an errexit a.k.a. set -e is not passed into a command substitution subshell (invoked with $(my-command) or backticks), but it is passed into a regular subshell (invoked with (...
1
vote
2
answers
103
views
Variables set inside the rcfile are NOT accessible through Python
I've a shell script and a python script organized as follows (CAN NOT change the directory structure):
~
├── a.py
├── b
└── c.sh
The MWEs are as follows:
c.sh
#!/bin/sh
rcfile=$(mktemp)
export ...
1
vote
1
answer
76
views
Why is command listing delaying the control release of a subshell?
In Bash, running the following:
( sleep 50 > /dev/null 2>&1 &) && exit 0
exits before my human eye can even notice.
But if I list commands within the group
( sleep 50 &&...
1
vote
1
answer
82
views
Why $BASH_SUBSHELL doesn't work with /bin/bash shebang
Doing some tests, I discovered that setting the bash shebang in a script would cancel the $BASH_SUBSHELL behavior.
# in the terminal
$ echo $BASH_SUBSHELL
0
$ (echo $BASH_SUBSHELL)
1
...
0
votes
4
answers
91
views
Problem with manipulating global variable within function in bash
Code is to match '(' with ')' and '{' with '}'. My problem is that the way I did is request to pop() is creating subshell. Is there a way to modify it with locale -n or some new features from bash 4.3&...
0
votes
0
answers
168
views
Bash: Forward keyboard input to background program?
I have a bash script where I spawn a program in a subshell and wait for it to finish:
#!/usr/bin/env bash
set -m
(
theprogram & echo $! > "${PROGRAM_PID}"
)
set +m
tail --pid &...
0
votes
1
answer
245
views
Chaining bash or dash commands with just a space instead of ; semicolon ; or && or &&
Normal command chaining methods work normally, for instance:
$ (SCRATCH='heya'; echo $SCRATCH)
heya
Or using the logic operator && yields predictable results:
$ (SCRATCH='heya' && ...
0
votes
3
answers
127
views
Linux shell: remove lines from an file reading another file
Let's consider 2 text file, one 'main_list', and one 'ignore_list'.
For each line in the ignore_list, I want to remove the line starting with that string in the main_line.
basically something doable ...
0
votes
0
answers
202
views
How to avoid subshell issues with reading lines from a file? [duplicate]
"Way back in the day", mid 1990s, I had to write a C program I called "readline" to avoid the global vs local variable issue created by subshelling when one did a construct like:
...
0
votes
1
answer
127
views
Why BASH_SUBSHELL is always 0 no matter `lastpipe` is enabled or not?
I have done some research on pipe and subshell
Each command in a multi-command pipeline, where pipes are created, is executed in its own subshell, which is a separate process (see Command Execution ...