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
1 answer

Bash script: how to skip a header line when sorting a text or csv file, while retaining it in the output

(Adapted from this: Join Manual, Header lines). I am sorting a file called file1 with this content: Name Age Charlie 34 Alice 25 If I just write: sort -k2b,2 file1 I get: Alice 25 Charlie 34 Name Age I can exclude the header from the sort…
FondDuLac
  • 21
  • 2
1
vote
2 answers

bash subshells vs bash -c

Bash subshells (cmd1;cmd2) whill run in a sub bash process, while it can access the variable not exported, how this can be? Meanwhile, bash -c structure can not access unexported variable but it also run in a new shell,so what's the…
kingkong
  • 119
  • 8
1
vote
0 answers

How to duplicate stdout to stdout and to a file without using a pipe?

I want to redirect the output of a for loop to a file and to stdout. So far I tried this but it actually forks the script : $ cat myScript.sh #!/usr/bin/env bash myVar1=X.Y.Z.T echo "=> BEFORE THE LOOP : myVar1 = $myVar1" for IP;do myVar1="$IP" …
SebMa
  • 4,037
  • 29
  • 39
1
vote
1 answer

How to bash pass command as an argument to function which run in sub shell?

This is my bash script. I want to pass a command as an argument and run it. case 1) is not working case 2) is working well. How can I make case 1) work? function menu(){ echo "[$@]" declare -a myarray while IFS= read -r input; do …
OfusJK
  • 676
  • 1
  • 5
  • 13
1
vote
0 answers

Make cannot be called from script without sourcing the script

I want to call the make command from a bash script in a MinGW bash shell. However the script seems to know "make" only when I call the script using source: build.sh: #!/bin/bash make all Calling source build.sh from the terminal works: The target…
1
vote
1 answer

Bash: set array within braces in a while loop? (sub-shell problem)

I'm having problems getting a variable "${Error[*]}", which is a regular indexed array, to stay set from the time it's declared until it's checked. It seems to me that a sub-shell must be launched so the declaration doesn't stick. I didn't think…
Aesthir
  • 347
  • 5
  • 12
1
vote
1 answer

Why does the ECHO command in a batch file FOR /F Loop always return "ECHO is on."?

Why does the ECHO command in the following batch always returns ECHO is on.? @ ECHO ON FOR /F "usebackq delims=" %%a in (`ECHO`) do (set EchoState=%%a) @ SET EchoState @ ECHO OFF ECHO @ ECHO for /F "usebackq delims=" %%a in (`ECHO`) do (set…
Peter Nimmo
  • 1,045
  • 2
  • 12
  • 25
1
vote
1 answer

Calling bash from within R

I have R generating some .csv files for another python program to run in another folder, I know it is possible to call bash from R but how could I call the command make in my ubuntu virtual machine in another directory?
Angus Campbell
  • 563
  • 4
  • 19
1
vote
1 answer

running server in tmux through ansible

(forgive me for spamming, I should have adjusted the original question, but it felt like I ran into a new hurdle when solving the problem) I set a goal of running a web server with ansible: figured I'd sit it inside a tmux session. I quickly ran…
alexakarpov
  • 1,848
  • 2
  • 21
  • 39
1
vote
1 answer

running a server in tmux with ansible

trying to setup a staging server for an API which I'm building using Django - and so far I was cutting corners, starting the thing using python manage.py runserver. But now that the setup grew a bit more complex, I decided to build an ansible…
alexakarpov
  • 1,848
  • 2
  • 21
  • 39
1
vote
0 answers

Stuck on Launching subshell in virtual environment

I am trying to set up a bot on my raspberry pi using the directions in the read me file. The first step is to paste some code into terminal which I did. after a little while of it installing some things like python and the github files it ends with…
joeshoes
  • 37
  • 2
1
vote
0 answers

What the interpretation of `ps --forest` when executing bash command groups?

According to the bash manual (https://www.gnu.org/software/bash/manual/html_node/Command-Grouping.html#Command-Grouping): ( list ) Placing a list of commands between parentheses causes a subshell environment to be created { list; } Placing a list…
Marcus
  • 5,104
  • 2
  • 28
  • 24
1
vote
1 answer

Terminate a bash script when assigning a function call into a variable

I have the following code to demonstrate: #!/bin/bash function demo() { echo "This is A" exit 1 echo "This is B" } input=$(demo) echo "${input}" echo "This is C" You can see if I run this script it will print out the following…
Kalib Zen
  • 655
  • 1
  • 5
  • 16
1
vote
2 answers

Running python files within the same shell

I'm starting out my adventure with Python, so I apologise if there are inaccuracies in my question. I have written a simple module with one command of: print("test") After saving the file to a .py extention I was trying to run it within a cmd…
ReeD
  • 11
  • 3
1
vote
1 answer

See/Count how many subshells a script has opened

Im having a conundrum with a script (or possible wsl2 memory leak). I'm running a large script (that takes 0.67 seconds to loop) My issue is that the loop time is slowly increasing, and so is the memory usage, so from 0.67 seconds / 0.9gig memory to…