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

How to exit a Subshell

Basically, I am trying to exit a subshell that contains a loop. Here is the code: ` stop=0 ( # subshell start while true # Loop start do sleep 1 # Wait a second echo 1 >> /tmp/output # Add a…
Feldspar15523
  • 165
  • 2
  • 11
0
votes
1 answer

Unexpected behavior with "set -o errexit" on AIX

This script shell works fine on GNU/Linux but not on AIX 5.3 #!/bin/sh echo $SHELL set -o nounset -o errexit [ 1 -eq 1 ] && { echo "zzz" } && echo "aaa" && [ 1 -eq 0 ] && echo "bbb" echo "ccc" On GNU/Linux, I've got the expected output…
Rémy J.
  • 21
  • 2
0
votes
2 answers

local variables in linux

When we export a local variable declared within a current shell does it get passed to future sub shells,processes , child processes or future child processes? I was told it get passed to future sub shells. Is it correct?
Char
  • 123
  • 10
0
votes
3 answers

How can I fix my bash array?

I am trying to create an array of file names so I can sort through a large file and take only the ones I want. My script looks like this set STATIONS = Kanto-station-names Where the folder "Kanto-station-names" has the names of files I want. This is…
Brock
  • 13
  • 1
  • 3
0
votes
1 answer

bash script to cd to value it reads from configuration file

I am having trouble with a bash script that is launched as a subshell from another shell. The script is installed in a number of different environments each of which have a variety of local-specific values set in a single config file per…
Fred Zimmerman
  • 1,178
  • 3
  • 13
  • 29
0
votes
1 answer

Echo within bash subshell

How do I call echo from within a bash subshell? This is behavior I want: # w=5 # echo $w > /tmp/x # cat /tmp/x 5 But: # cmd="echo $w > /tmp/x" # $cmd 5 > /tmp/x And: # $( $cmd ) bash: 5: command not found
0
votes
3 answers

Using Python to send commands to a subshell

I need to send commands to shell "MYSHELL>" after it has been initiated. prcs = subprocess.Popen("MYSHELL; cmnd1; cmnd2;",shell=True, subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) outputPrcs, err = prcs.communicate() print…
0
votes
2 answers

Bash for-loop not continuing even when body is launched in background subshell (works in zsh)

When I run the following script in bash: #!/bin/bash names=("ALL" "no_C" "no_R" "no_Q") for name in $names; do export name=$name mkdir -p $name ( echo 'selection' 'System' | gmx cluster -f ${name}_protein_only.trr -s…
0
votes
2 answers

Passing content of bash script to be executed in same shell given by binary file execution

Time ago i had this answer but i cannot recall how exactly was the syntax. I have two files. One is binary file called "changeuid" and second is "do.sh". I need to run changeuid which will change my uid and after execution, content of do.sh, which…
soundhax
  • 155
  • 3
0
votes
1 answer

pgrep -P $$ gives an inexistent process id

#!/usr/bin/env bash sleep 3 & # Spawn a child trap ' pgrep -P $$ # Outputs one PID as expected PIDS=( $( pgrep -P $$ ) ) # Saves an extra nonexistant PID echo "PIDS:…
Dude
  • 11
  • 4
0
votes
2 answers

Run generated commands in same shell in order to access defined function

In my Bash script, I'm generating a string which contains a series of commands. Some of these commands are references to a function defined within this script. That is: function myfunc() { ...} } cmds=`echo "echo hello"; echo myfunc` # contrived,…
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
0
votes
0 answers

Implementing a subshell Unix C

I'm trying to implement a subshell in C. I already have a normal shell, which looks like this: int status; pid = fork(); if (pid < 0) { exit(1); } else if (pid == 0) { if (execvp(node->command.program, node->command.argv) < 0) { …
Steven
  • 1,123
  • 5
  • 14
  • 31
0
votes
1 answer

How to set variables in a subshell?

I have a script which will be running in each server and copies certain files into it. Script knows where I am running and what files I need to copy. Script will copy files from local datacenter local_dc but if it is down or not responding, then it…
john
  • 11,311
  • 40
  • 131
  • 251
0
votes
2 answers

DB2 Output to Variable via bash script

I'm hoping someone can help with applying the output from a db2 command to a variable to use later on in a script. So far I am at... db2 "connect to user using " while read HowMany ; do Counter=$HowMany echo…
Richard C
  • 401
  • 1
  • 5
  • 19
0
votes
0 answers

running bash script having subshell commands from php

I'm trying to execute a child script in bash through php shell_execute("$command") whose contents are like below. $command=$_GET['command']; $op2=shell_exec("$command"); echo "Command $command output is
  $op2 
"; On submit I get Command…
pythonRcpp
  • 2,042
  • 6
  • 26
  • 48