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
1
vote
2 answers

Assign the result of a mathematical calculation to a variable without a subshell

My question is a twofold. First: Is it possible to achieve this without using a subshell? FOO=$((6-5)) or this? BAR=`echo "$FOO/100" | bc -l` If I understand the second one correctly, I'm creating 2 subshells by using ´ and | Second Does…
Lord Otori
  • 349
  • 1
  • 4
  • 17
1
vote
2 answers

Passing commands to a subshell with xargs does not work inside an alias

I was trying to build a quick script to find all the git repos under a directory and sequentially "git pull" each one. This is what I found so far: find ~/ -name ".git" -type d | sed 's,/*[^/]\+/*$,,' | xargs -L1 bash -c 'cd "$1" && git pull' _ If…
lelandbatey
  • 193
  • 1
  • 1
  • 13
1
vote
3 answers

Exiting ruby in subshell without killing parent

I have Ruby programA that calls Ruby programB with: system("ruby programB.rb ") Under certain conditions, I want programB to terminate its operation (and the associated subshell) but allow programA to continue on to the next set of…
JESii
  • 4,678
  • 2
  • 39
  • 44
1
vote
2 answers

alias in xargs sourcing tcsh

I am trying to run an xargs command that uses an alias. Searching came up with this alias gojk 'stsq \!:1 | xargs -t -0 -I {} tcsh -c source ~/.tcshrc.user;myset {}' but it returns Bad ! arg selector and variations will return source: too few…
3dbeing
  • 11
  • 2
1
vote
1 answer

Why using double backslashes in sed for running ssh?

I ran across the following in Gentoo Linux's wiki about dynamic jumphost list: ProxyCommand ssh $(echo %h | sed 's/+[^+]*$//;s/\([^+%%]*\)%%\([^+]*\)$/\2 -l \1/;s/:/ -p /') nc -w1 $(echo %h | sed 's/^.*+//;/:/!s/$/ %p/;s/:/ /') It works, but I…
user183394
  • 1,033
  • 1
  • 11
  • 20
1
vote
2 answers

How do I terminate everything at a certain subshell level in Bash, without using "kill 0"?

Context: Say I have: ( #outer subshell { #inner command group, pipe-connected to ensure simultaneous invocation do_first_thing #die, somehow } | { #inner command group, pipe-connected to ensure simultaneous…
Zac B
  • 3,796
  • 3
  • 35
  • 52
1
vote
1 answer

shell script, subshell, sub script, pipe - WEIRD (?) CTRL+C SIGNAL PROPAGATION

So, I've identified a behaviour of my bash script that I find weird. Here is a test script: echo "start of script" ( echo "start of subshell" cat > /tmp/$$ << EOF trap 'exit 99' SIGINT echo "sleep 10, hit ctrl+c now" sleep 10 EOF chmod +x…
FloG
  • 463
  • 5
  • 9
0
votes
3 answers

Make target substitution

It seems that the subshell does not retrieve the result of "$@", so there is nothing to do substitution on. %_bust.css: %.css @echo $(echo $@ | sed s/_bust/$(BUSTER)/g)
hkjels
  • 51
  • 2
0
votes
3 answers

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 with sed and a while loop. E.g. while read line;…
EricBDev
  • 1,279
  • 13
  • 21
0
votes
0 answers

How to avoid subshell issues with reading lines from a file?

"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: while read line do my_var=$(echo "$line" | cut -f 12 -d ":") if…
Richard T
  • 4,570
  • 5
  • 37
  • 49
0
votes
1 answer

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 Environment). If the lastpipe option is enabled…
matrixzj
  • 33
  • 5
0
votes
0 answers

BASH: Variables in a function piped to dialog are lost

I have a script with a function which does some stuff and sets some variables to be used later in the script. This function is also echoing progress (echo 10, echo 20 etc.) and is piped to a "dialog --gauge" to display a progress bar. After the…
0
votes
0 answers

Checking if subprocess was terminated by user

# Create a new terminal window and run the ffmpeg command in it cmd = ' '.join(ffmpeg.compile(output_stream, overwrite_output=True)) compressing = subprocess.Popen('start cmd /k {}'.format(cmd), shell=True) while compressing.poll() is None: #check…
Mohamed Darwesh
  • 659
  • 4
  • 17
0
votes
0 answers

How I switch to the subshell that opened by previous command on remote Linux VM when connected using paramiko on Python?

Few details about my setup: Developing on Python Using Paramiko to SSH connect to the Linux (ubuntu) VM Problem: When I ssh to the VM I am executing commands while part of the commands are openning a subshell. As a result code hangs and I can't…
msqa
  • 1
  • 1
0
votes
3 answers

How can I store a subshell PID in a variable so that I can kill the subshell and its background process later?

So, let us say I am running a subshell with a background process as follows: (command &) I want to be able to store the PID of this subprocess into a bash variable so that I can kill the subshell and its running background process later. How can I…
Gigi Bayte 2
  • 838
  • 1
  • 8
  • 20