- I found a very good blog on this issue, you can see if it helps, here is a link: < font size = "3" > use the grep command parsing < / font > < / a > < / li >
Look at the code. grep without $will filter out two lines, but adding $only leaves one line. Why, the first and second lines end in autoRunVms.sh, Why does the first line not filter out after adding $?
[root@localhost home]# ps aux | grep autoRunVms.sh
root 27559 0.0 0.0 112660 976 pts/0 S+ 15:21 0:00 grep --color=auto autoRunVms.sh
root 30205 0.0 0.0 113648 2068 ? S 2月08 2:49 /bin/bash /usr/local/VmsServerV3.140.0/autoRunVms.sh
[root@localhost home]#
[root@localhost home]# ps aux | grep autoRunVms.sh$
root 30205 0.0 0.0 113648 2068 ? S 2月08 2:49 /bin/bash /usr/local/VmsServerV3.140.0/autoRunVms.sh
0 Answer
This answer quotes ChatGPT
In regular expressions, the $sign indicates the end of the matching string. Therefore, when you filter with "autoRunVms.sh$", only lines ending in "autoRunVms.sh" will be matched.
In the first line of output, you can see that there are two strings containing "autoRunVms.sh" : one is the command for the grep process itself, and the other is the command for the process you are searching for. Since the grep command also contains "autoRunVms.sh", when you filter with "autoRunVms.sh", both commands will be matched. But when you filter with "autoRunVms.sh$", only the end of the second command matches the regular expression, so only the second command is filtered out.
Therefore, if you want to match all lines that contain "autoRunVms.sh", use "autoRunVms.sh" to filter. If you only want to match lines ending in "autoRunVms.sh", use "autoRunVms.sh$" for filtering.
这家伙很懒,什么都没留下...