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

Shell script on remote server terminates ssh session

I have a shell script written by some vendor and does a lot of low level stuffs under the hood which I have no domain specific knowledge on. I have a manual given by the vendor how to execute this script on the CLI manually. it works as expected if…
electricalbah
  • 2,227
  • 2
  • 22
  • 36
0
votes
0 answers

bash read into array

can you please tell me why this is not working? only the add 'e f' after the read loop is done, but not the multiple adds 'q w' inside the read loop. regards stefan vuser1@vpc1:~$ echo ${#a[@]} 1 vuser1@vpc1:~$ ls Desktop Documents Downloads …
0
votes
1 answer

How to execute new bash command inside shell script file?

How can I put the follow script to work properly? 1 #/bin/bash 2 3 # some commands 4 5 bash 6 # a lot of commands 7 # ... 8 exit 9 10 bash 11 # A lot of other commands 12 # ... 13 exit 14 15 exit 0 The problem is that when executing the…
Blane John
  • 65
  • 6
0
votes
1 answer

Open editor from bash script and cat file to variable not working

Why doesn't this work? There has to be a very simple answer to this. I have two bash scripts. The first script calls the second which opens an editor on a tmp file, once user quits, cat the file which will be assigned to a variable in the first…
ram
  • 680
  • 5
  • 15
0
votes
1 answer

Get current time (and date) WITHOUT opening a subshell

Is it possible to get current time ( and possibly date ) without doing it via a subshell? because if I'm not mistaken, this command do open a subshell? d=$(date)
0
votes
1 answer

How to append text from bash to vim?

I know about r! command to append text from bash output to vim under cursor. So for example issuing this command in vim: :r! printf "abcd\n" would append "abcd" into the vim buffer. But I am somehow unable to do similar with subshell involved. In…
milanHrabos
  • 2,010
  • 3
  • 11
  • 45
0
votes
2 answers

Exiting entire bash script from subshell

I'm a bit new to bash scripting, I have a C++ program communicating back and forth with this bash script through some named pipes. I used inotifywait to watch a folder for new files and when a new file is added (ending in .job) sending it to through…
Adam Jean-Laurent
  • 205
  • 1
  • 2
  • 8
0
votes
0 answers

Bash script in background with control posibility

I want to create the script which runs function in background, but leaves ability to query that function about results, pause, resume or other way to interact with it. For simplicity, lets say, i want to run the counter in the background which…
Petras L
  • 183
  • 1
  • 1
  • 7
0
votes
0 answers

Modify global variable from subshell loop in bash

My objective is to measure the current system load as a percentage, and then blink an LED for that percentage of a second. To do this I had a function "get_load" which measures the average load over a second, in a while loop, and was running this as…
0
votes
3 answers

Wrong exit code for variable function call assignment in subshell

I have a script which quite often fails. It is crucial that the correct exit code is passed on. This code works as expected: #!/usr/bin/env bash function my_function { echo "Important output" exit 1 } function cleanup { MY_EXIT_CODE=$? …
cis
  • 1,259
  • 15
  • 48
0
votes
1 answer

Getting the exit code of a Python script launched in a subshell with Bash

I want to run a Bash script every minute (through a CRON entry) to launch a series of Python scripts in a granular (time-wise) fashion. So far, this is the script I've made: # set the current date DATE=`date +%Y-%m-%d` # set the current system time…
Julio María Meca Hansen
  • 1,303
  • 1
  • 17
  • 37
0
votes
1 answer

How do Python subshell and Linux shell produce different results?

I have a folder with subfolders containing .pp Puppet manifest files. I found out that I can use puppet strings tool to convert .pp files into json. This can be easily achieved using Unix terminal, running command puppet strings generate --format…
0
votes
0 answers

Execute tcsh script from bash and keep tcsh session interactive

I have tcsh script (as shown below), which I want to execute in csh from the bash shell, and want to maintain the tcsh session at the end of the file. #!/bin/csh setenv var1 value1 set var2 value2 # ----- some code ----- I would like to have…
Ganesh Gore
  • 113
  • 1
  • 2
  • 8
0
votes
0 answers

How to set parent variable in { grouped } shell commands?

#!/bin/bash FOO=1 { FOO=2; echo "a"; } echo $FOO # prints 2 { FOO=3; echo "b"; } | wc echo $FOO # prints 3 How come the assignment FOO=2 is visible to the rest of the script, but the assignment FOO=3 isn't? What's special about the pipe into wc…
Lucian Wischik
  • 2,160
  • 1
  • 20
  • 25
0
votes
2 answers

Bash: quoted array expansion leads to strange results

While experimenting with bash arrays, I stumbled upon behaviour I find hard to explain. > arr=("a" "b") > bash -c "echo ${arr[*]}" a b > bash -c "echo ${arr[@]}" a The relevant part of the bash manual states: ${!name[@]}, ${!name[*]} : If name is…