Questions tagged [subshell]

A subshell refers to a shell invoked from within a parent shell. It is an example of a child process. Questions with this tag may involve any issue with working with subshells. Please also include tags for platform or shell language.

Most questions with this tag involve the Bash shell, as that is a very popular shell language. However this could relate to any platform, command-line application, or shell that allows the creation of subshells.

295 questions
0
votes
1 answer

why bash read command create a loop-local variable?

I wrote following bash script. The read command creates variable var. if $var==5 then break loop. seq 10 | while read -r var do echo "read: $var" if [[ $var == 5 ]]; then echo "break loop: $var" break fi …
PeopleMoutainPeopleSea
  • 1,492
  • 1
  • 15
  • 24
0
votes
1 answer

How to force script.sh to run as subshell not child?

I have several kinds of buildA.sh, buildB.sh, ... scripts which compile some codes. I also have a general script common.sh which do pre-process, set environments and set trap command. cat common.sh ~~~ ./buildA.sh #call build.sh, other build.sh…
OfusJK
  • 676
  • 1
  • 5
  • 13
0
votes
1 answer

Bash Subshell Expansion as Parameter to Function

I have a bash function that looks like this: banner(){ someParam=$1 someOtherParam=$2 precedingParams=2 for i in $(seq 1 $precedingParams);do shift done for i in $(seq 1 $(($(echo ${#@}) - $precedingParams)));do …
CraigR8806
  • 1,584
  • 13
  • 21
0
votes
1 answer

Can I open a shell prompt from within NodeJS?

I'm in a NodeJS command-prompt session and I want to dip out to shell for a few commands and come back to my session with variables intact. I remember doing this as a kid using "!" in another environment - can I do something like that in Node?
user1944491
  • 559
  • 1
  • 8
  • 24
0
votes
2 answers

How to find the number of instances of current script running in bash?

I have the below code to find out the number of instances of current script running that is running with same arg1. But looks like the script creates a subshell and executes this command which also shows up in output. What would be the better…
Hipster1206
  • 411
  • 6
  • 13
0
votes
3 answers

modify array with command substitution

Im trying to modify array to manage some functionality. I want to access the array lst from the subshell or use somtheing that isnt command substitution for catching the function output. I have changed the code for better…
emal
  • 11
  • 5
0
votes
3 answers

bash how to error out when subshell error

I have a script with the following command to upload a bunch of zip files to a site: find . -name "*.zip" -exec echo {} \; -exec sh -c 'err=$(curl -s --data-binary "@{}" http://mystorage.com | jq -r ".error"); if [ -z $err ] || [ $err = "file…
lnthai2002
  • 154
  • 11
0
votes
0 answers

How can I get output of command of a sub shell in C

i am trying to implement a simple bash shell in C, which has to handle pipes and subshells. The main problem is that once I run the command in the subshell, how can I pass the output to the parent process to use the pipe? the idea behind my program…
federikowsky
  • 518
  • 2
  • 8
0
votes
1 answer

How to timeout complex processes in bash?(process with child-processes of its own)

The process in context here is 'android build environment'. To timeout normal tasks, one would do #Timeout command 'do_task' in 10 seconds timeout 10s do_task However, when I try the same with android build environment, it doesn't seem to…
0
votes
0 answers

Bash - exit does not exit script (only subshell)

The topic proposed from the moderator does not answer this question. The exit command in the following script is supposed to exit the entire script. Which normally happens if you put an exit command into a function. But not in this case:…
theerrormagnet
  • 174
  • 2
  • 15
0
votes
0 answers

Running 'bash -i' in re-invoked script (via sudo -S) exits immediately - why?

When I launch the following script, it restarts as root, the new bash shell opens up, but "something" sends an "exit" command immediately and the script runs to its end. #!/bin/bash #set -x PASSWORD= echo At start: $$ if [[ $EUID -ne 0…
0
votes
1 answer

why does subshell returns if: command not found

Let's assume the following script: echo "if test 1 -eq $1 ; then echo ls;fi" | tee /tmp/toto cat /tmp/toto $(cat /tmp/toto) While running it with this command: ./non_secure_script 1 I get the following error: if: command not found However, the…
Guillaume D
  • 2,202
  • 2
  • 10
  • 37
0
votes
1 answer

scp doesn't list then when run in subshell script

I have a bash script my_script which executes: scp -- 'somehost:*.txt' dest_dir now, when I run this script from an interactive shell session, scp lists files as it copies them. But when I run a second script, containing: exec 5>&1 foo=$(my_script…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
1 answer

Does git bash create a subshell by default when running a script file?

Im exploring a bit on shell scripts and wrote this script. When the build command fails, it has to provide an error message and exit. I know that exit 1 would close the current shell its running on. And the exit statement is within a curly braces…
Niveditha Karmegam
  • 742
  • 11
  • 28
0
votes
1 answer

Visualize subshells/processes for command

Sometimes shell commands behave unexpectedly because of subshells-processes. A recent example I experienced was that this command won't work because xargs runs the cd-command in a subshell: ls | sort | tail -1 | xargs cd Another one is that cd…
Kaligule
  • 630
  • 3
  • 15