Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the role of semicolons in Bash?

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what is the role of semicolons in Bash". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the role of semicolons in Bash"?

The semicolon, which plays a special role in shell, is similar to pressing enter in PS1. It is mainly used in the following scenarios and usually brings great convenience.

1 multi-line command, single-line input.

(2) use with sleep.

3 if there are a series of commands, each command needs to be executed for a long time, you can enter it at once without waiting for the first command to finish executing before running the second command.

Example:

1 multi-line command, single-line input

Command 1; command 2; command 3

Echo'I am here'; echo'I am not here'; echo'in fact, I am here today

2 used with sleep, similar to 5 4 3 2 1 intermediate break

Echo 'CTRL C to cacel'; sleep 10; echo' Done'

More than 3 commands that take a long time are entered at one time and executed slowly.

Sleep 500; sleep 500; sleep 500

Echo $$; echo $$; echo $$

But why on earth does the semicolon play this role? That is, why is it executed sequentially instead of concurrently? Look at this command:

Echo $$; echo $$; echo $$

21304

21304

21304

You will find that the output is a PID, that is, all three commands are executed in the same process. -sequential execution.

That is, the same sentence, the semicolon, which is considered the end of a command in shell, is similar to typing a command in shell and pressing enter.

Ps-ef | grep pts/0

Root 21302 1582 0 Dec26? 00:00:00 sshd: root@pts/0

Root 21304 21302 0 Dec26 pts/0 00:00:00-bash

Root 28290 21304 0 09:55 pts/0 00:00:00 ps-ef

Root 28291 21304 0 09:55 pts/0 00:00:00 grep pts/0

At this point, I believe you have a deeper understanding of "what is the role of semicolons in Bash". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report