0

I am learning nanomsg with its example. But the command line below made me confused.

./pipeline node0 ipc:///tmp/pipeline.ipc & node0=$! && sleep 1

I can understand that ./pipeline refers to the executable file and node0 together with ipc:///tmp/pipeline.ipc are the parameters passed to the program. The & symbol means the command is executed in the background. According to this answer, if node0=$! executed successfully then the terminal will sleep for 1 second. Here comes the problem:

What does node0=$! mean? Especially what does $ and ! mean here?

nnzzll
  • 328
  • 1
  • 9
  • 1
    As the documents provided to you by @jhnc state, the symbolic gibberish `$!` is translated in the following way. The `$` character introduces parameter expansion of the special parameter `!`. Ergo, as the documentation states, the combination `$!` expands to the process ID of the job most recently placed into the background. In short, the variable `node0` will have the PID assigned of the `pipeline` command. – kvantour Aug 18 '22 at 09:18

1 Answers1

2

"$" and "!" does not mean anything (only literals). But "$!" does mean something.

"$!" is the PID of the last program sent to background.

Example:

$ sleep 60 &
[1] 21657
$ echo $!
21657

And node0 is a variable with the PID of the previous command sent to background (./pipeline in this case).

Note: the PID may differ.

sudoer
  • 154
  • 7