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

Time multiple commands without a subshell?

Is there a way to use the time reserved word in zsh to time multiple commands, without starting a subshell? I know that this works: { time ( sleep 5 sleep 3 PROMPT='foobar> ' ) } However the parentheses mean that a subshell is created,…
Kevin Burke
  • 61,194
  • 76
  • 188
  • 305
0
votes
2 answers

How to fetch last argument and stop before last arguments in shell script?

I want to merge all files into one. Here, the last argument is the destination file name. I want to take last argument and then in loop stop before last arguments. Here code is given that I want to implement: echo "No. of Argument : $#" for i in $*…
LoveToCode
  • 296
  • 2
  • 18
0
votes
1 answer

propagating a variable in a for loop bash

I have 15 paths stored in a array variable, and file names, also stored as another array variable and I want to bind each path to its corresponding file. I was looking for sth that will bind each path element with its corresponding file like…
Guy
  • 3,535
  • 2
  • 12
  • 9
0
votes
3 answers

Iterating over filenames from a pipeline in bash

Consider me frustrated... I've spent the past 2 hours trying to figure out how to have a command that has pipes in it pump that output to a for loop. Quick story on what I'm attempting followed by my code. I have been using xbmc for years. However,…
bassmadrigal
  • 121
  • 8
0
votes
2 answers

git branch vs $(git branch)

When I execute git branch on the command line I get a list of all the branches on a repo, however when I execute $(git branch) in a sub-shell, it first prints out a list of files in the top level folder in a repo before printing out the branch…
Andrew De Andrade
  • 3,606
  • 5
  • 32
  • 37
0
votes
5 answers

bash: how to display the name of the first directory that contains a certain file

I have this: ls */file dir1/file dir2/file dir3/file But I need just the first directory name, like this: dir1 I did this: IFS="/" read foo bar <<< "$(ls */file 2>/dev/null)" echo $foo dir1 And it works, but now I have a problem with subshell…
Ulrik
  • 1,131
  • 4
  • 19
  • 37
0
votes
2 answers

ksh --> is it possible to run a command on the parent shell (main shell) from within a subshell?

#!/usr/bin/ksh if [ $# -ne 1 ]; then echo "[*]\t Please see usage..." echo "[*]\t Usage: $0 " exit 1 fi if [ -z "$1" ]; then echo "[*]\t Please see usage..." echo "[*]\t Usage: $0…
0
votes
0 answers

Read input from file and pass it to sub shell

i have a scenario where in i have to monitor jobs which run in different servers, The job details(job name, host server, etc) are present in a dat file. I have written a script a script which reads the details from the dat file and calls a local…
0
votes
0 answers

BASH: how to store subshell variables into an array?

I have array1, array2 and a function. I am trying in a for j=0 to ARRAY_SIZE loop to get the data from array2[j], pass it to a function and the returning output store it in array1[j]. Below is the part of the code that I am working on: exec…
0
votes
2 answers

How can I use read timeouts with stat?

I have the following code: #!/bin/bash read -t1 < <(stat -t "/my/mountpoint") if [ $? -eq 1 ]; then echo NFS mount stale. Removing... umount -f -l /my/mountpoint fi How do I mute the output of stat while at the same time being still able to…
Ville
  • 4,088
  • 2
  • 37
  • 38
0
votes
1 answer

bash redirection via xterm and mpg123

Here is a part of my .fluxbox/startup file (a=($(grep "^1 " $HOME/Documents/4.n3u|awk '{print "/home/g" $2}'|sort -R|head -20)); \ xterm -e mpg123 -C ${a[@]} &>$HOME/Documents/mpg123.dat &) As written, the redirection fails, all such output…
user985675
  • 293
  • 3
  • 10
0
votes
2 answers

Unix Subshell inheriting the command history from parent bash

I have written a series of python tools that spawn new bash sessions. I am want those individual subshells to inherit the command history of the parent. I have tried: shopt -s histappend PROMPT_COMMAND="history -an;$PROMPT_COMMAND" in the…
0
votes
1 answer

Using the db2 variable "DB2DBDFT" to connect to default schema with user / using

I am trying to write a bash script that does some db2 work. I am facing the issue whereby subshells require db2 connections to be reconnected. Unfortunately, reconnecting every time is dog slow, as around 1000 new connections will need to be made,…
Mitch Kent
  • 574
  • 5
  • 23
0
votes
1 answer

Subshell MySQL-query in bash

I'm trying to set variable in the cycle in Ubuntu bash, which is getting recordset from database, but this variable is setting to its previous value. Here is a code: #!/bin/bash PREV_FILE_PATH="127" while true do echo "$PREV_FILE_PATH" …
Peter
  • 159
  • 1
  • 4
  • 10
0
votes
4 answers

Substituting command echo with "echo -e" on linux

I have a shell program that has content like this !#/bin/bash echo \\n program Once I run this program on a platform other than Linux it recognizes the special character and gives the output as (newline) program When the same program runs on…
1 2 3
19
20