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

Bash array fails to populate if function is executed as if condition

I have a function which populates a global bash array #!/bin/bash # Array to store debugger IDs ID=() fill_id() { for i in 1 2 3 4 5 do ID+=( $i ) done echo "fill_ids - entries in ID: ${#ID[*]}" } If function is…
Shubham
  • 628
  • 1
  • 9
  • 19
0
votes
1 answer

Passing subshell to bash function

I have a set of bash log functions which enable me to comfortably redirect all output to a log file and bail out in case something happens: #! /usr/bin/env bash # This script is meant to be sourced export SCRIPT=$0 if [ -z "${LOG_FILE}" ]; then …
jabozzo
  • 591
  • 1
  • 6
  • 17
0
votes
0 answers

How to write to a coprocess from a child process of the parent that opened the coprocess

I am using a coprocess inside my main parent process to spawn commands to a shell that otherwise cannot be solved (the shell that I open in the coprocess is not maintained by me and executes the "newgrp" and "exec" commands that stop me from sending…
0
votes
1 answer

Bash Shell Calculating Sum of All Video durations inside a folder in MAC OS

I used to get my result in windows by just searching *.mp4 and select all files. The sum of duration would show in side panels details. I want to find the same things inside MAC recursively. This is the script I wrote in bash. Tell me what I am…
0
votes
0 answers

How to tell if my c program is running inside a subshell?

Is there a possibility to know if my program, written in C, is running inside a subshell or a normal shell? I want to know because I am unable to suspend it when it's running inside a subshell.
Glitch
  • 155
  • 1
  • 9
0
votes
1 answer

quote/escape output from local builtin to pass back to itself with builtins only?

Edit: Mostly rewritten for clarity/digestibility. Also, I found one possible answer using xargs. I prefer avoiding the external command--I'll only accept my own answer if no alternative turns up. I'm trying to pass the output of local (declared…
abathur
  • 1,047
  • 7
  • 19
0
votes
1 answer

Can I avoid this subshell in a POSIX sh script?

I am trying to comprehend how, if even it can be done, can I avoid subshell? Is this the only way the code can be written or is there another way? I tried to use braces { ... }, but it won't pass shellcheck and won't run. is_running_interactively…
Vlastimil Burián
  • 3,024
  • 2
  • 31
  • 52
0
votes
2 answers

Shell : Removing "eval" in favor of something that can host external variables, is itself a variable and contains a subshell

I've read this : Parentheses for subshell don't work when stored in a variable and this : http://mywiki.wooledge.org/BashFAQ/048 and they've been insightfull and instructive and I've enjoyed reading them. I did not find therin a solution to a…
tatsu
  • 2,316
  • 7
  • 43
  • 87
0
votes
1 answer

Makefile multiline command does not work in Docker properly

I am trying to compile HTML from Markdown. My makefile looks like: MD = pandoc \ --from markdown --standalone # ... $(MD_TARGETS):$(TARGET_DIR)/%.html: $(SOURCE_DIR)/%.md mkdir -p $(@D); \ $(MD) --to html5 $< --output $@; \ sed -i…
Nick Roz
  • 3,918
  • 2
  • 36
  • 57
0
votes
1 answer

How to avoid subshell behaviour using while and find?

Because I trapped into this myself, I asked a question and did give also the answer here. If find iterates over what the command did find, this is executed from bash in a subshell. So you can not fill an array with results and use it after your…
ingobaab
  • 87
  • 4
0
votes
1 answer

strange behaviour of a subshell executing command with arguments

when I execute the following command directly: root@busybox-694d76bb5d-2gcvh:/# mysql -hmariadb -P3306 -uroot -ppassword -e 'SELECT 1' I get the following output: mysql: [Warning] Using a password on the command line interface can be…
Tom Klino
  • 2,358
  • 5
  • 35
  • 60
0
votes
2 answers

Execute Batch in Powershell (Win 10) does not affect Parent Shell

just for understanding this. I want to open my Powershell in a certain folder. As I didn´t find out how, I tried to put a batch file with just "cd ....." in it in the default folder where PowerShell opens. When I execute the batch, though, I end up…
0
votes
2 answers

How to capture output of bash command group (curly braces) in environment variable

For example, I can do this with a subshell: VAL=$( do_something ) but how do I achieve the same thing with curly braces so the command is NOT executing in a subshell? I.e. this does not work: VAL={ do_something; } TIA.
ccbunney
  • 2,282
  • 4
  • 26
  • 42
0
votes
1 answer

How to use a grep command in a subshell?

i want to connect to 4 servers via bashscript and execute on each server some commands. The output of the commands should be saved in a variable locally. So i tried this peace of code. I've already tried several things. When i just execute an "ls"…
xMaNuu
  • 31
  • 1
  • 7
0
votes
1 answer

Bash script save csv in array and search for part of string

after editing my script I would shortly like to explain what i want to do: Check if files are in Folder Look at begin of file name search for file less than 1 hour old take the file and do sqlldr ..if this succeeds move file to an other folder…
Swoop
  • 49
  • 1
  • 10