Based on @user3100381’s answer, here’s a much simpler command to get the same thing which I believe should be fairly portable:
PARENT_COMMAND=$(ps -o comm= $PPID)
Replace comm=
with args=
to get the full command line (command + arguments). The =
alone is used to suppress the headers.
See: http://pubs.opengroup.org/onlinepubs/009604499/utilities/ps.html
Related Contents:
- Why is $$ returning the same id as the parent process?
- How do I iterate over a range of numbers defined by variables in Bash?
- Command not found error in Bash variable assignment
- How to get a password from a shell script without echoing
- Aborting a shell script if any command returns a non-zero value
- Can a shell script set environment variables of the calling shell? [duplicate]
- How to join multiple lines of file names into one with custom delimiter?
- How to add a progress bar to a shell script?
- How to check the exit status using an ‘if’ statement
- An example of how to use getopts in bash
- How to highlight bash/shell commands in markdown?
- Running multiple commands in one line in shell
- Capturing Groups From a Grep RegEx
- How to put a line comment for a multi-line command [duplicate]
- Can I export a variable to the environment from a Bash script without sourcing it?
- “unary operator expected” error in Bash if condition
- How do I run a shell script without using “sh” or “bash” commands?
- ‘find -exec’ a shell function in Linux
- [ :Unexpected operator in shell programming [duplicate]
- How do I fetch lines before/after the grep result in bash?
- While loop stops reading after the first line in Bash
- Asynchronous shell commands
- Press alt + numeric in bash and you get (arg [numeric]) what is that?
- How to get the last part of dirname in Bash
- envsubst: command not found on Mac OS X 10.8
- Indenting multi-line output in a shell script
- Find multiple files and rename them in Linux
- How to declare 2D array in bash
- How can I make bash tab completion behave like vim tab completion and cycle through matching matches?
- How to add a timestamp to bash script log?
- Is there any reason to use bash over zsh? [closed]
- Make ls print it all on one line (like in terminal)
- The PID of a bash child proccess (imapsync) – how do you get it?
- in linux terminal, how do I show the folder’s last modification date, taking its content into consideration?
- How to schedule to run first Sunday of every month
- How to suppress Terminated message after killing in bash?
- Append line to /etc/hosts file with shell script
- How to parse XML using shellscript? [duplicate]
- ZSH not recognizing my aliases?
- self-deleting shell script
- Trying to retrieve first 5 characters from string in bash error?
- How to detect 386, amd64, arm, or arm64 OS architecture via shell/bash
- Detect if PATH has a specific directory entry in it
- Passing arguments by reference
- Shell Script, read on same line after echoing a message
- Using jq to fetch key value from json output
- How to check if another instance of my shell script is running
- What does the `2>` mean on the Unix command-line?
- Is it possible to get the function name in function body? [duplicate]
- How to get the first column of every line from a CSV file?