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

Bash command fails with bash -c but works in an interactive shell

I have this fairly simple command that, when ran inside bash, outputs the remaining disk space to stdout: echo -n "External1TB: $(grep -Poi '(\/mnt\/External1TB\s+)\K(.*)' <(df -H --output=target,avail))B" I'm using process redirection <() to pipe…
bool3max
  • 2,748
  • 5
  • 28
  • 57
0
votes
2 answers

Variables inside a bash script subshesll

I am trying to run commands as root and capture the output into a variable. However the variable "loopdev" is returning as empty. sudo bash << "EOF" whoami loopdev=`losetup -f --show "${image}"` echo "####" $loopdev "####" EOF The normal output for…
Bob R
  • 605
  • 1
  • 13
  • 25
0
votes
1 answer

shell: redirect output stream to a function while keeping access to variables

I would like to redirect the output stream of a command to a function so I did this: function aClassicCommand { sleep 1 echo "this is logs" } ############################## function logsReceiver { read IN echo "received logs:…
Cl00e9ment
  • 773
  • 1
  • 13
  • 30
0
votes
1 answer

Change directory from python script for calling shell

I would like to build a python script, which can manipulate the state of it's calling bash shell, especially it's working directory for the beginning. With os.chdir or os.system("ls ..") you can only change the interpreters path, but how can I apply…
Paul Würtz
  • 1,641
  • 3
  • 22
  • 35
0
votes
2 answers

Bash subshell input with variable number of subshells

I want to grep lines from a variable number of log files and connect their outputs with paste. If I had a fixed number of outputs, I could do it thus: paste <(grep $PATTERN $FILE1) <(grep $PATTERN $FILE2) But is there a way to do this with a…
JellicleCat
  • 28,480
  • 24
  • 109
  • 162
0
votes
1 answer

sh shell redirecting a subshell to file, can't find the right syntax

i want to run a sed command with programatically with changing parameters. the thing is that i cant find the correct syntax to do so. i want to configure a conf file with this and change a dir path to another. i'm currently using: RESULT=$("sed…
David Gidony
  • 1,243
  • 3
  • 16
  • 31
0
votes
0 answers

Why, in Ruby, backticks and `system()` have different blocking behavior when calling `xdg-open`?

Based on the Ruby documentation, both backticks and system() have the same blocking behavior (that is, they are both blocking calls). When I use them to execute a call to xdg-open though (which in itself, forks the system process, for example…
Marcus
  • 5,104
  • 2
  • 28
  • 24
0
votes
1 answer

launch subshell with different cwd and pass env variables

I want to launch a subshell with its CWD to be of the child process, not the parent and at the same time pass in env variables. REGION=$1 DEFAULT_MARKET=$2 NODE_ENV=$3 (cd ../core-services && exec PORT=3008 REGION=$REGION…
RJ Mohammad
  • 101
  • 1
  • 12
0
votes
1 answer

zenity --auto-kill: Killing a subshell does not kill its child processes?

I am having a really hard time understanding the behaviour of zenity --progress --auto-kill. It appears to not kill its parent process' subprocesses but to detach them somehow. Consider the following shell script…
NobodyInPerson
  • 115
  • 1
  • 11
0
votes
3 answers

After subshell ends, "wait" waits for ENTER command

Given a file with a list of tables to Sqoop, this script launches a Sqoop import command with a list of options. The intel here is in the "scheduler", which I borrowed from here, meaning that I want the script to launch no more than a max number of…
Omar
  • 309
  • 1
  • 2
  • 10
0
votes
1 answer

Two ways of running a command checked with if

Both of these work. The first is shorter, but I'm guessing the second is safer or better - running the command inside $() If so, could someone explain why the second is safer, better, etc. if my_function "something" ; then ... if $(my_function…
user7347805
0
votes
1 answer

Bash script not echoing new lines in echo subprocess

When I run this script on my terminal it works perfectly with the newline echo -e $(echo "a \na") Outputs: a a When I wrap this up in a bash script - test.sh: #!/bin/sh echo -e $(echo "a \na") And I call ./test.sh, I get this output: -e a…
ClickThisNick
  • 5,110
  • 9
  • 44
  • 69
0
votes
0 answers

Executing bash cd command in Makefile

So I am writing some assembly code which is then compiled by a Makefile: # linking main: main.o # ld -o build/main build/main.o -melf_i386 # compiling main.o: main.s # as -o build/main.o main.s --32 I had to add build directory, cause I…
minecraftplayer1234
  • 2,127
  • 4
  • 27
  • 57
0
votes
5 answers

Using a command in echo gives a different result

I am running the following commands on FreeBSD: $ cat filename | tr '\t' '\n' #Output DOCS : ON NLS : ON RCSI : ON $ echo `cat filename | tr '\t' '\n'` #Output DOCS : ON NLS : ON RCSI : ON Why is echo not displaying…
0
votes
2 answers

bash—Return status from function in background

I have a bash script with roughly the following structure: function download { # download a big file } function prepare_stuff { # prepare some stuff } function process_download { # process the downloaded file } download &…
user149408
  • 5,385
  • 4
  • 33
  • 69