Today, I learned a little bit about the shell programming under Linux and simply recorded the test cases.
1. Edit the shell script file as follows:
#!/bin/bash
echo "Hello Bash Linux"
echo "No. 0 parameter: $ A"
echo "First parameter: $ $"
echo "Current child shell process: $$"
#pidarr = ' PS x | awk ' {print '} '
pidarr=$ (ps x | awk ' {print $} ')
Echo $pidadd
For ID in $pidarr
Do
echo "$id"
Done
2. Save As file Test.bash
3. Make the file have an execution property, use the following command
chmod +x Test.bash
Sample Script Description:
(1) The first line of #!/bin/bash is a fixed format for the script file, indicating that there is bash in the bin directory to perform
(2) The 8th line of pidarr=$ (PS x | awk ' {print $} ') represents the PS x | The results of awk ' {print '} ' are stored in the variable Pidarr, where the awk command is a useful command, and the detailed use of the method can be Baidu
Linux Shell Programming Example-get process ID