What does $$ FOO do in bash (in a deb package built with epm)?

At the command prompt, I get the following:

$ FOO=foo $ echo $FOO foo $ echo $$FOO 11971FOO 

Here $$ resolves the shell PID, as expected, and "FOO" is printed verbatim.

Now, trying to understand and debug some scenarios, I found the following:

 #!/bin/bash FILE1=/path/to/file/1 FILE2=/path/to/file/2 echo $$FILE1 >> $$FILE2 

The script arises from the postinstall script of the Debian package. Is he supposed to have to undergo pre-processing before he can work?

Update: the script is part of a package created using epm and read using the following directive:

 %postinstall <script.sh 

In the resulting package, the deb postinst script reads:

 #!/bin/bash FILE1=/path/to/file/1 FILE2=/path/to/file/2 echo $FILE1 >> $FILE2 

Thus, the processing is performed either using epm or dpkg.

+5
source share
2 answers

This is apparently a feature of the EPM packaging tool. Documentation citation:

Please note that all commands specified in the list file will use the variable extension provided by EPM, so be sure to include any dollar signs ($) in your commands. For example, $ foo is replaced with the value foo, but $$ foo becomes $ foo.

+2
source

$$ displays process id 11971 in your case.

Since you have FOO after that, echo just unloads FOO after 11971 , so you get

 11971FOO 

To be precise, this is the process id of the bash shell in which you will start the session. To check this, you can do:

 kill -9 11971 

which will end the current session. Below script in normal cases

 #!/bin/bash FILE1=/path/to/file/1 FILE2=/path/to/file/2 echo $$FILE1 >> $$FILE2 

will not be pretreated. It will continue to add the file.

 current_shell_process_id_FILE2 

in the current directory with contents

 current_shell_process_idFILE1 
0
source

Source: https://habr.com/ru/post/1238952/


All Articles