Skip to main content

Questions tagged [subshell]

Use where a shell is run inside a shell (nested shells)

Filter by
Sorted by
Tagged with
0 votes
2 answers
145 views

So, I was playing around with this answer, when I found that neither printf_stdin () { read input printf "$input" } sed "/lorem ipsum foobar/ { s/'/'\"'\"'/g s/\...
Grass's user avatar
  • 145
5 votes
1 answer
291 views

If do this on my bash terminal: ( (sleep 0.5 && echo 'first command, second result' &); (echo 'second command, first result' &); ) then I see: second command, first result ...
k0pernikus's user avatar
  • 16.7k
4 votes
2 answers
349 views

I have a command that takes always the same initial parameters. I can create a variable to capture these parameters. Also, I need to pass the output of a subshell running the same command to the ...
k314159's user avatar
  • 533
4 votes
4 answers
551 views

Given this code: #!/bin/bash set -euo pipefail function someFn() { local input_string="$1" echo "$input_string start" sleep 3 echo "$input_string end" } function ...
k0pernikus's user avatar
  • 16.7k
0 votes
2 answers
103 views

My login shell is Fish, but I would like to execute a shell command (apt install ...) as if my login shell was Bash. Is it possible to make a command/subprocess believe that my login shell is /usr/bin/...
Alexey's user avatar
  • 2,380
4 votes
0 answers
100 views

Why does echo "$(fc -l -1)" show the previous command, but echo "$(fc -l -1 | cat)" show the current command? $ testfc () { > echo "$(fc -l -1)" > echo &...
Jacktose's user avatar
  • 532
0 votes
0 answers
38 views

I have a script which is supposed to fetch 2 URLs sequentially: #!/bin/bash wget_command='wget --restrict-file-names=unix https://www.example.com/{path1,path2}/' $($wget_command) echo $wget_command ...
MonkeyZeus's user avatar
5 votes
2 answers
345 views

mkfifo foo printf %s\\n bar | tee foo & tr -s '[:lower:]' '[:upper:]' <foo wait rm foo This is a working POSIX shell script of what I want to do: printf %s\\n bar is symbolic for an external ...
finefoot's user avatar
  • 3,586
1 vote
0 answers
93 views

In Bash blocks {} and subshells () the exit early doesn't work if there is an OR condition following it. Take for example set -e { echo a; false; echo b; } || echo c prints a b and set -e { echo a; ...
QuickishFM's user avatar
5 votes
1 answer
351 views

I'm experiencing extremely sluggishness in opening subshells (by using ` ` or $( ) command substitutions in scripts) while in ksh on some Linux servers. The same problem does not exist in sh or any ...
Paul W's user avatar
  • 183
1 vote
0 answers
26 views

This command is a simplification of the problem I've come across: ssh grinder1h.devqa sh -c "cd /etc/ssh && pwd" This command gives an output of "/home/fetch", which is ...
CryptoFool's user avatar
3 votes
0 answers
197 views

I have a Debian 12 (bookworm) host where I run three VMs using QEMU / KVM. To simplify VM management, each VM has a QEMU monitor socket. These sockets are /vm/1.sock, /vm/2.sock and /vm/3.sock. Among ...
Binarus's user avatar
  • 3,951
0 votes
1 answer
83 views

there is a script, 1.sh. 1.sh starts 1a.sh and then 1b.sh. But how to exit all scripts, how to exit 1.sh and how to not start 1b.sh if 1a.sh breaks with an error?
user447274's user avatar
-2 votes
1 answer
95 views

About bash For a new tty when is executed the echo $SHLVL command it displays 1 as expected. Now, if in the same tty is executed the bash command and later again the echo $SHLVL command it displays 2. ...
Manuel Jordan's user avatar
0 votes
1 answer
445 views

You can give a Flatpak permissions to access files/folders outside of its sandbox using the techniques described in this Ubuntu Stack Exchange QA. But is it possible to give an existing Flatpak ...
Amazon Dies In Darkness's user avatar
2 votes
1 answer
123 views

SC1143 suggests that commented parts of a wrapped shell command to be wrapped in a subshell. Is the Posix shell "smart enough" to not launch a subshell when it sees that it does nothing? ...
AvidSeeker's user avatar
1 vote
1 answer
54 views

Main question: how would one get the delta for declare -F, between that in the current shell, and that as if the shell just started (first two commands below). $(declare -F) does not solve the ...
Erwann's user avatar
  • 729
4 votes
1 answer
404 views

So if I input the command like below, a sub-process (PID 4920) is created by the subshell. linuxprobe@DESKTOP-TP0G72N:~$ (sleep 2;ps -f --forest;sleep 5) UID PID PPID C STIME TTY ...
joe's user avatar
  • 53
3 votes
2 answers
496 views

In my book (Sobell's A Practical Guide to Linux, 4e) it is written that You can use the parentheses control operator to group commands. When you use this technique, the shell creates a copy of itself,...
EE18's user avatar
  • 253
0 votes
2 answers
236 views

A variant of this question has been asked a few times (here and here, for instance) but I'm afraid that the answers either didn't fully capture my question here or else perhaps assumed more than I ...
EE18's user avatar
  • 253
0 votes
1 answer
127 views

I employ ncdu, the NCurses Disk Usage tool, in conjunction with zsh and p10k. Pressing 'b' triggers the spawning of a shell in the current directory. How can I present this information on-screen to ...
alecail's user avatar
  • 1,663
2 votes
1 answer
123 views

In which order are the distinct steps of this bash command done: (flock -n 9) 9> toto.txt If I do only the subshell part: (flock -n 9) I get this result: flock: 9: Mauvais descripteur de fichier (...
Laurent Lyaudet's user avatar
0 votes
1 answer
108 views

I have this: timeout 25 bash -c ' for i in {1..9}; do if read line < "$my_fifo"; then if test "$line" != "0"; then exit 0; ...
Alexander Mills's user avatar
1 vote
1 answer
434 views

GNU bash, version 4.3.27 I'm running into an odd issue with a script that writes output to a file. The script ssh's to a list of servers and records the state/substate of a few services. I then store ...
Juts's user avatar
  • 28
0 votes
2 answers
105 views

I want to ignore all pre-existing env variables, and echo just one, like this: env -i <( export foo=bar; env ) and this would just print: foo=bar however, the construct of env -i <() ...
Alexander Mills's user avatar
0 votes
1 answer
739 views

I have a bash script set up to monitor a number of UDP streams and convert it into actionable data. My problem is that I need to set the script to periodically check to see if the stream capture is ...
Dan D's user avatar
  • 3
-1 votes
1 answer
74 views

cat <(echo yes) Displays "yes". And running this inside sh -m results in the same thing on Bash 5.2.15. Yet on Bash 4.4.20 it throws an error: sh -c "cat <(echo yes)" sh: -c:...
Zaz's user avatar
  • 2,654
-1 votes
2 answers
318 views

I'm a beginner at Linux shell, but I know that this command creates a subshell: Subshells are typically created using subshell operators or commands such as parentheses (), backticks `, or the $() ...
gremo's user avatar
  • 167
1 vote
1 answer
189 views

I've found similar problems on stackexchange, but never close enough to my case to help. I'm trying to create a script and bind it to a key, so that when pressed, it displays "title by artist&...
Dr. Coomer's user avatar
3 votes
1 answer
309 views

Is this difference between executing code in the shell or in a sub-shell expected? $ a() { echo ${@: -1} ; } $ echo "echo ${*: -1}" > b $ chmod +x b $ a 1 2 3 3 $ ./b 1 2 3 bash $ Debian ...
gboffi's user avatar
  • 1,406
4 votes
2 answers
1k views

I have a script that works fine, but runs in series. I would like to have the script take each line from a text file and run/spawn that line in a subshell and then move onto the next line and so on. I ...
Steve Rowe's user avatar
0 votes
1 answer
745 views

This question is different from In Bash, how can I detect if I'm in a subshell? because it's not shell specific. Let's say I open a terminal, which is zsh. I can go deep into that like this, $ ...
Evan Carroll's user avatar
  • 35.2k
0 votes
2 answers
3k views

Contrived example: #!/usr/bin/bash MYVAR=$(cat /somedir | grep -i myval) Now I want: #!/usr/bin/bash BASEDIR=/somedir MYVAR=$(cat [BASEDIR?] | grep -i myval) How should variable be passed to ...
paulj's user avatar
  • 238
0 votes
1 answer
180 views

When a subshell is entered, traps that are not being ignored shall be set to the default actions Source: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_28 Apparently,...
finefoot's user avatar
  • 3,586
10 votes
2 answers
2k views

Scripts typically start with a shebang such as #!/usr/bin/env bash, which specifies the shell to be used for execution. The execution behavior when the shebang is not present seems to be up to the ...
Jonathan H's user avatar
  • 2,523
0 votes
1 answer
2k views

This function will either use cURL or wGet to download a script and execute it with additional arguments: wexec() { url=$1 shift if command -v "curl" >/dev/null 2>&1; ...
Martin Braun's user avatar
1 vote
1 answer
3k views

I'm writing some bash code, and I'd like the script to exit if there's any error. The set -e trick works pretty well, but not with subshells. Here's a simplified example: set -e chmod a=r file.txt x=`...
jyoung's user avatar
  • 117
0 votes
1 answer
637 views

Consider multiple subshells, each writing its own log file. Consider that one subshell failed, leading to sending (using some mechanism) of SIGTERM to all the subshells. Upon reception of SIGTERM all ...
pmor's user avatar
  • 757
1 vote
1 answer
196 views

Consider this code: job() { local id=$1 sleep $id } do_job_in_parallel() { local pids=() # run subshells for id in $(seq 4) do job $id & pids=("${pids[@]}" $!) ...
pmor's user avatar
  • 757
1 vote
2 answers
1k views

How do I get the FZF Preview Window to Display Functions from my Current Bash Environment? I want to list my custom bash functions using FZF, and view the code of a selected function in the FZF ...
user2514157's user avatar
2 votes
1 answer
580 views

I am trying to use regex for capturing some text pattern in an ouput of a command and create an array list_mqs. The problem is that this previous command get stuck and never terminates. So, when I use ...
dcubaz's user avatar
  • 23
0 votes
0 answers
51 views

From help declare: -p display the attributes and value of each NAME Just running declare -p works as expected. So does running it in a subshell with (declare -p). However, when using echo &...
rewire's user avatar
  • 111
0 votes
1 answer
54 views

_select () { apt-cache search '' | fzf \ --prompt='search: '\ --marker="M" \ --ansi \ --layout=reverse \ --cycle \ --multi \ --inline-info \ --preview "...
testoflow's user avatar
  • 147
0 votes
1 answer
337 views

I'm curious why this special device is needed to fork the command and run it asynchronously in the minimal Busybox shell. BusyBox v1.30.1 (Debian 1:1.30.1-4) built-in shell (ash) Enter 'help' for a ...
round-down's user avatar
0 votes
2 answers
583 views

So I have this: ( set -eo pipefail; { set -eo pipefail; file_path="$(echo "$i" | jq -r '.file_path')" if [[ -n "$file_path" ...
Alexander Mills's user avatar
0 votes
2 answers
141 views

Sorry if the title is bad (it is already the best one I can think of). Anyway, here is the line of code: printf "%s\n" "$(echo a b "c d") Simple code. Of course, I will ...
sudoer's user avatar
  • 65
0 votes
1 answer
522 views

I'm trying to determine if a git add action has created any expected modifications, and the following works in an interactive shell $ BASE_DIR=foo/bar/baz $ git add "${BASE_DIR}" $ git ...
Bruno Kim's user avatar
  • 239
1 vote
1 answer
229 views

Can you tell me, why I have to # shellcheck disable=SC2030 in the following script? get_names_and_hosts(){ unset LOCAL_HOSTS declare -a LOCAL_HOSTS unset LOCAL_NAMES declare -a LOCAL_NAMES ...
Chris G.'s user avatar
  • 163
0 votes
2 answers
271 views

I need to create a reusable ("utility") script handling entire set of operations with temporary files for any of my other ("application") scripts: creation tracking of temporaries ...
wass rubleff's user avatar
1 vote
4 answers
355 views

I'm not used to linux scripting and this is the first time I'm working on it so I'm struggling with the following problem: Code: while [ $pct -gt 80 ]; do flag=1; ls -tr | while read file; do ...
Biswadeep Sarkar's user avatar

1
2 3 4 5