Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

subshell

How to pipe multiple commands into a single command in the shell? (sh, bash, …)

June 30, 2023 by Tarik

Use parentheses ()’s to combine the commands into a single process, which will concatenate the stdout of each of them. Example 1 (note that $ is the shell prompt): $ (echo zzz; echo aaa; echo kkk) | sort aaa kkk zzz Example 2: (setopt; unsetopt; set) | sort

Categories bash Tags bash, pipe, process, shell, subshell Leave a comment

Set a parent shell’s variable from a subshell

February 17, 2023 by Tarik

The whole point of a subshell is that it doesn’t affect the calling session. In bash a subshell is a child process, other shells differ but even then a variable setting in a subshell does not affect the caller. By definition. Do you need a subshell? If you just need a group then use braces: … Read more

Categories bash Tags bash, shell, subshell Leave a comment

How to effectively abort the execution of a Bash script from a function

January 5, 2023 by Tarik

What you could do, is register the top level shell for the TERM signal to exit, and then send a TERM to the top level shell: #!/bin/bash trap “exit 1” TERM export TOP_PID=$$ function func() { echo “Goodbye” kill -s TERM $TOP_PID } echo “Function call will abort” echo $(func) echo “This will never be … Read more

Categories bash Tags bash, exit, function, subshell Leave a comment

Why is $$ returning the same id as the parent process?

October 20, 2022 by Tarik

$$ is defined to return the process ID of the parent in a subshell; from the man page under “Special Parameters”: $ Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the current shell, not the subshell. In bash 4, you can get the process … Read more

Categories bash Tags bash, pid, shell, subshell Leave a comment

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa