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

eliminate subshells for faster process?

I've read that scripts that are calling for a subshell are slow, which would explain why my script are slow. for example here, where I'm running a loop that gets an number from an array, is this running a subshell everytime, and can this be solved…
1
vote
0 answers

Using while read, do Loop in bash script, to parse command line output

So I am trying to create a script that will wait for a certain string in the output from the command that's starting another script. I am running into a problem where my script will not move past this line of code $(source path/to/script/LOOPER >>…
cdraper
  • 147
  • 2
  • 7
1
vote
2 answers

How can I add commands to be executed when setting a view?

Using cleartool, when you cleartool setview, a subshell is opened apparently (you can exit it and leave the view). I was wondering - how can I get more commands to be executed, or settings made, when this subshell starts? Of course, I don't mean…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
1 answer

Run a subshell as root

Consider you have a Linux/UNIX machine with Bash. You have a file secret.txt that only root can read. You want to use a command that takes a string as an argument, say, sample-command Log in as a root user and run the command using the…
Culip
  • 559
  • 8
  • 24
1
vote
1 answer

How do I execute a command in a subshell in Rust?

In Python, I could do os.system("pip install bs4"). Is there any equivalent in Rust? I've seen std::process::Command, but this seems to fail each time: use std::process::Command; Command::new("pip") .arg("install") .arg("bs4") .spawn() …
1
vote
1 answer

Test command inside git bisect run script doesn't work

I'm using git bisect to find out a version in which the VERSION file has changed from 0.0.1_testing to newer version and I want to use bisect run like this. git bisect run sh -c 'if [ "$(cat VERSION)" == "0.0.1_testing" ] ; then exit 0 ; else exit…
second32
  • 83
  • 1
  • 9
1
vote
2 answers

Parent trap visible but not run by subshell

Tested for Bash 5.0.2 According to the GNU Bash Reference Manual, Bash performs the expansion [of a command substitution] by executing [the] command in a subshell environment According to The Open Group Base Specifications Issue 6: when a…
Marcus Rossel
  • 3,196
  • 1
  • 26
  • 41
1
vote
0 answers

How to get around subshell problem with sudo and file permissions

I have a specific problem. Here's a simplified example: File /opt/test is owned by root. Has file permissions of 700. I need to cp /opt/test /home/user/. So I need this exact command set in my sudoers file. I can't open up permissions to any…
jasonmclose
  • 1,667
  • 4
  • 22
  • 38
1
vote
1 answer

How to get error code from a subshell run within eval

I have tried looking for a questions similar to this that cover a solution for me, but none that I could find quite answer my exact question. I would like to run a command within a subshell within an eval call and obtain the status code returned by…
Ian Tait
  • 607
  • 1
  • 8
  • 16
1
vote
1 answer

exit 1 if a file is empty other wise continue to the next step

I am writing a bash script. Step 1 - Fetch some meta data via curl and write to a file. Step 2 - Check if the file is empty. If the file is empty, log out "File is empty. Exiting..." and exit with status code 1. If the file is not empty,…
user4889345
1
vote
1 answer

Get bash sub shell output immediately from named pipe

I have a few commands i run between brackets which i then redirect to a named pipe and tail the pipe however it looks like the redirection happens only after the block has finished executing as i don't see any output from the tail command for a…
Snipzwolf
  • 533
  • 1
  • 8
  • 22
1
vote
1 answer

How can I get Hex conversion working in sh

I want to make a script /bin/sh compatible. At some point I was using a print-out of a hex variable to its decimal value but it is throwing this error: sh: 1: arithmetic expression: expecting EOF: "16#c0" That error is not present when the script…
user8162
  • 391
  • 3
  • 12
1
vote
0 answers

Bash Associative Array Being Overwritten While Run in For Loop

I'm trying to write a bash script that uses a function to spawn several applications in the background, and then store their PIDs in an associative array with the application name as the key. Running into a problem as I'm using a for loop to loop…
1
vote
2 answers

Wait for the subshell in Bash IO redirection

The scenario is that I need my main command to run in current shell, this is required or losing all environment stuff, etc. So, I can't just run my pipe this way: #command-line 1 mainCommand | ( ...subshell commands... ) & #this wait works, but…
Dee
  • 7,455
  • 6
  • 36
  • 70
1
vote
1 answer

Execution order of subshells?

While trying to solve other problems, I have come across the following bash script in Alex B's answer in this question: #!/bin/bash ( # Wait for lock on /var/lock/.myscript.exclusivelock (fd 200) for 10 seconds flock -x -w 10 200 || exit 1 #…
Binarus
  • 4,005
  • 3
  • 25
  • 41