subshell Questions

5

Solved

ksh has a really interesting construct to do this, detailed in this answer: https://mcmap.net/q/41292/-capture-stdout-and-stderr-into-different-variables Since Bash 4.0, there is a builtin mapfile...
Latria asked 7/2, 2014 at 15:51

8

Solved

I was using the "exit 1" statement in my Bash functions to terminate the whole script and it worked fine: function func() { echo "Goodbye" exit 1 } echo "Function call wi...
Annexation asked 27/3, 2012 at 16:25

5

Solved

I've written a python program. And if I have a shebang like this one: #!/usr/bin/python and I make the file executable with: $ chmod 755 program.py I can run the program like so: $ ./program...
Joiner asked 28/1, 2017 at 20:54

4

Solved

initiate () { read -p "Location(s) to look for .bsp files in? " loc find $loc -name "*.bsp" | while read do if [ -f "$loc.bz2" ] then continue else filcount=$[$filcount+1] bzip $loc fi if [...
Estrade asked 5/9, 2011 at 23:13

7

Solved

I am using a Jenkinsfile in a pipeline on version 2.32.2. For various reasons I want to extract the version string from the pom. I was hoping I wouldn't have to add the maven help plugin and use ...
Negris asked 2/3, 2017 at 23:56

4

Solved

How can I get exit code of wget from the subshell process? So, main problem is that $? is equal 0. Where can $?=8 be founded? $> OUT=$( wget -q "http://budueba.com/net" | tee -a "file.txt" ); ...
Levirate asked 14/2, 2012 at 13:36

8

Solved

I have problem with Bash, and I don't know why. Under shell, I enter: echo $$ ## print 2433 (echo $$) ## also print 2433 (./getpid) ## print 2602 Where getpid is a C program to get current pid, li...
Virgy asked 11/1, 2014 at 14:57

3

I'm trying to get around a problem that seems to me you cannot pass open db2 connection to a sub-shell. My code organization is as follows: Driver script (in my_driver.sh) # foo.sh defines baz() ba...
Literal asked 22/3, 2016 at 15:33

2

Solved

I'm sure I'm missing something simple, but I'm using an executive script to call a few utility scripts and I want to handle all of the output from the utilities via one pipe. My issue is the utilit...
Pitre asked 24/10, 2013 at 17:17

11

Solved

How do I set a variable in the parent shell, from a subshell? a=3 (a=4) echo $a
Dowager asked 21/3, 2013 at 7:1

4

When I type ls -l $(echo file) output from bracket (which is just simple echo'ing) is taken and passed to external ls -l command. It equals to simple ls -l file. When I type ls -l (echo file) we h...
Winfrid asked 23/8, 2016 at 20:53

2

Solved

This question is not cygwin specific. However, in the cygwin mail archive https://cygwin.com/ml/cygwin-announce/2010-08/msg00015.html are various instructions for setting the cygwin specific igncr ...
Epistyle asked 12/5, 2015 at 3:3

1

Solved

Usually I capture the output via a subshell: result="$(command 2>&1)" If the command is source, the subshell swallows some (all?) changes to the scripts shell's environment. How ca...
Glut asked 27/3, 2021 at 13:26

4

Solved

The problem: I cannot update an array in a while loop. An illustration (not the actual problem): declare -A wordcounts wordcounts["sentinel"]=1000 ls *.txt | while read f; do # assume that that l...
Holmun asked 3/10, 2013 at 15:48

2

Solved

The folder structure like this: folder_01 ├── folder_02├──Dockerfile_02 ├── folder_03├──Dockerfile_03 & example.sh In the example.sh script, I want to use cd to navigate back to folder_02 an...
Hew asked 22/5, 2020 at 13:34

5

Solved

How can I figure out if a file descriptor is currently in use in Bash? For example, if I have a script that reads, writes, and closes fd 3, e.g. exec 3< <(some command here) ... cat &l...
Theater asked 12/1, 2017 at 1:42

3

Solved

I have a simple shell script with the following preamble: #!/usr/bin/env bash set -eu set -o pipefail I also have the following function: foo() { printf "Foo working... " echo "Fa...
Siegel asked 14/11, 2019 at 14:49

2

Solved

I have a program that reads from two input files simultaneously. I'd like to have this program read from standard input. I thought I'd use something like this: $program1 <(cat) <($program2) ...
Buddhism asked 17/3, 2017 at 5:35

1

Because I trapped into this myself, I asked a question and did give also the answer here. If find iterates over what the command did find, this is executed from bash in a subshell. So you can...
Chlorohydrin asked 19/3, 2019 at 11:29

1

Solved

When running this script: #!/bin/sh -ex if [[ $# -ne 1 ]]; then echo "./import-public-ssh-key.sh <absolute path to public key>" exit 1; fi PATH=$1 KEY=$(basename ${PATH}) I get: ...
Neufer asked 29/12, 2018 at 16:39

1

Solved

I'm confused over whether bash variables are exported to subshells and when they are accessible by scripts. My experience so far led me to believe that bash variables are automatically available to...
Briny asked 17/8, 2018 at 22:51

2

I know that subshells have their stdout suppressed from the caller's output: a=$(echo 123) echo a:$a This outputs, as expected: a:123 But why isn't stderr suppressed as it's in a subshell? a...
Resuscitator asked 8/11, 2017 at 14:50

2

Solved

echo hello | read str echo $str This read is executed after the pipeline, which means that the output of the echo gets read into str - but because it is after a pipe, the contents of str are now i...
Helenahelene asked 26/10, 2017 at 6:3

0

Consider the following command $ bash -c " sleep 10000 | sed 's/ Something//g '" The process tree due to that command looks like this; \-+= 69771 hbaba -bash \-+= 39225 hbaba bash -c sleep 1...
Towers asked 21/10, 2017 at 7:10

4

Solved

I've seen a lot of answers and comments on Stack Overflow that mention doing something to avoid a subshell. In some cases, a functional reason for this is given (most often, the potential need to r...
Gendron asked 24/2, 2014 at 0:15

© 2022 - 2024 — McMap. All rights reserved.