[LINUX] [sh] How to store the command execution result in a variable

I use it when I want to execute a command in the shell, divide the result, and store it in a variable.

$ set $(echo "1 2 3" | awk -F" " '{print $1, $2, $3}' )
$ echo $1
1
$ echo $2
2
$ echo $3
3

Combined with the ps command, the zombie process with PPID = 1 I'm using it to get rid of it.

cmd="Zombie process name"   #Zombie process created by bugs
ppid=1                  # PPID=1

ps all | while read F UID PID
do
    set $(ps o pid,ppid,cmd -p $PID | tail -n1 | awk -F" " '{print $1, $2, $3}'
    if [ $ppid = $2 ] && [ $cmd = $3 ] ; then
        sudo kill -9 $PID
    fi
done

Recommended Posts

[sh] How to store the command execution result in a variable
How to pass the execution result of a shell command in a list in Python
How to pass the execution result of a shell command in a list in Python (non-blocking version)
How to check the memory size of a variable in Python
How to output the output result of the Linux man command to a file
How to embed a variable in a python string
How to get the variable name itself in python
How to write a GUI using the maya command
A memorandum of how to execute the! Sudo magic command in Jupyter Notebook
I want to store the result of% time, %% time, etc. in an object (variable)
How to execute a command using subprocess in Python
[Linux] How to put your IP in a variable
How to use the __call__ method in a Python class
How to generate a query using the IN operator in Django
How to get the last (last) value in a list in Python
In the python command python points to python3.8
linux / c> link> Get the execution result of the shell command in the C program> I was taught how to use popen ()
How to determine the existence of a selenium element in Python
How to get all the possible values in a regular expression
How to make a command to read the configuration file with pyramid
How to get a string from a command line argument in python
[Introduction to Python] How to use the in operator in a for statement?
How to check the memory size of a dictionary in Python
How to monitor the execution status of sqlldr with the pv command
How to get the vertex coordinates of a feature in ArcPy
I made a command to display a colorful calendar in the terminal
[Linux] How to use the echo command
How to use the Linux grep command
How to get a stacktrace in python
How to hide the command prompt when running python in visual studio 2015
How to specify a .ui file in the dialog / widget GUI in PySide
Enclose the cat result in double quotes and put it in a variable
[Linux] Command to get a list of commands executed in the past
How to get a value from a parameter store in lambda (using python)
How to sort by specifying a column in the Python Numpy array.
How to read standard input or variable files at the same time like paste command in Python
How to calculate the volatility of a brand
How to use the C library in Python
How to receive command line arguments in Python
How to clear tuples in a list (Python)
How to implement Discord Slash Command in Python
How to create a JSON file in Python
How to implement a gradient picker in Houdini
How to notify a Discord channel in Python
How to create a shortcut command for LINUX
How to get the files in the [Python] folder
[Python] How to draw a histogram in Matplotlib
How to create a Rest Api in Django
How to write a named tuple document in 2020
How to count numbers in a specific range
How to read a file in a different directory
Create a command to get the work log
How to Mock a Public function in Pytest
How to mention a user group in slack notification, how to check the id of the user group
Try to solve the traveling salesman problem with a genetic algorithm (execution result)
[NNabla] How to get the output (variable) of the middle layer of a pre-built network
How to count the number of elements in Django and output to a template
I made an appdo command to execute a command in the context of the app
How to get a list of files in the same directory with python
Try to build a pipeline to store the result in Bigquery by hitting the Youtube API regularly using Cloud Composer
Read the Python-Markdown source: How to create a parser