What is the meaning of file name ending with .$$?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What is the meaning of file name ending with .$$?
# 1  
Old 07-21-2016
What is the meaning of file name ending with .$$?

Hello Sirs,

I'm trying to understand what does it mean when a file name ends with ".$$"

Like in the below snippet.

Code:
 if [ $isnext = n -o $isnext = N ]; then
	cat /tmp/input0.$$ >> $filename

Please help me understand it. Thanks in advance.
# 2  
Old 07-21-2016
Hi, $$ is a variable that contains the process id of the shell. It is used in tmp directories, to make it less likely that one process interferes with a temporary file of another process and that the temporary files do not share the same name.

from the man page:
Code:
$$: Expands to the process ID of the shell.  In a () subshell, it expands  to  the process ID of the current shell, not the subshell.


Last edited by Scrutinizer; 07-21-2016 at 05:52 PM..
These 2 Users Gave Thanks to Scrutinizer For This Post:
# 3  
Old 07-22-2016
So, if you write to a file containing $$ you are fairly sure (but not guaranteed) to have a unique file.

Code:
$ echo "Hello World!" > /tmp/myfile.$$
$ ls -l /tmp/myfile*
-rw-rw-r--. 1 rbatte1 users 48 Jul 22 14:15 /tmp/myfile.22384

Within the same script/shell, you can read the files back again because the $$ will still have the same value.


I hope that this helps.
Robin
This User Gave Thanks to rbatte1 For This Post:
# 4  
Old 07-22-2016
Thank you for your help guys. I appreciate your valuable time.
# 5  
Old 07-22-2016
A more reliable method (bot still not infallible) would be to create a temporary directory. You can then happily write files there and set a trap to clean up when your script ends. If you have mktemp installed then consider something like this:-
Code:
#!/bin/bash

tmpdir=$(mktemp -d) || exit 1                        # Abort script if we cannot do this!
if [ -z "$DEBUG" ]
then
   trap "rm -rf $tmpdir" EXIT
else
   printf "Debug mode\n"
fi

echo "Hello world!" > $workdir/output.file

If the variable DEBUG has a value then the directory is not removed so you can go and have a look afterwards. If you don't set it or set or you actively unset it, then the trap will be switched on and the directory removed at the end to reduce the risk of conflicts later.

If you don't have mktemp then you can just try it using:-
Code:
tmpdir=/tmp/tmp.dir.$$
mkdir -m 700 $tmpdir || exit 1                        # Abort script if we cannot do this!
...
...
...



I hope that this helps,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove '.' from file for numbers ending in '.'

Hi, I have numerous files which have data in the following format A|B|123.|Mr.|45.66|33|zz L|16.|33.45|AC.|45. I want to remove decimal point only if it is last character in a number. O/p should be A|B|123|Mr.|45.66|33|zz L|16|33.45|AC.|45 I tried this sed -e 's/.|/|/g' Problem... (6 Replies)
Discussion started by: wahi80
6 Replies

2. Shell Programming and Scripting

Remove certain lines from file based on start of line except beginning and ending

Hi, I have multiple large files which consist of the below format: I am trying to write an awk or sed script to remove all occurrences of the 00 record except the first and remove all of the 80 records except the last one. Any help would be greatly appreciated. (10 Replies)
Discussion started by: nwalsh88
10 Replies

3. Shell Programming and Scripting

Finding File Names Ending In 3 Random Numerical Characters

Hi, I have a series of files (upwards of 500) the filename format is as follows CC10-1234P1999.WGS84.p190 each of this files is in a directory named for the file but excluding the extension. Now the last three numeric characters, in this case 999, can be anything from 001 to 999, I need to... (3 Replies)
Discussion started by: roche.j.mike
3 Replies

4. SCO

File name ending with @

Hi Current SCO Unix 5.05 I see that there are filenames with @ at the end of file name for example in the /usr/lib there is file lpadmin@ what does the @ represent when it is at the end of the file name Thanks (4 Replies)
Discussion started by: atish0
4 Replies

5. Shell Programming and Scripting

sed in script creates output file ending with '?' (^M)

Hi, I'm trying to use sed within a shell script (bash, running ubuntu). The command works fine from the command line, but when I use it within the script, rather than creating a file with the name I've specified, it creates one that ends with a question mark '?' when you use ls, e.g.... (3 Replies)
Discussion started by: jennykay
3 Replies

6. Shell Programming and Scripting

How to open file ending with @.

Hi i want to know the content of files that ends with @ in /bin directory like ls@ etc. (4 Replies)
Discussion started by: bhavesh.sapra
4 Replies

7. Shell Programming and Scripting

Deleting lines ending with . from a file

HI I'm looking to delete lines ending with .tk from below data file --------- abc.tk mgm.tk dtk mgmstk ------ I have written below code ---- sed '/.tk *$/d' dat_file.txt > temp.txt ---- But its deleting all the lines ending with tk. I need to delete only the lines ending .tk my... (5 Replies)
Discussion started by: shekhar_v4
5 Replies

8. Solaris

removing particular lines ending with a .cnt extension in a text file

I have a text file with rows of information (it is basically a ls command information(o/p from ls command)) I need to remove the lines ending with a .cnt extension and keep the lines ending with .zip extension, how to accomplish this. I also only need the date,size and name of the file from every... (2 Replies)
Discussion started by: ramky79
2 Replies

9. UNIX for Dummies Questions & Answers

File- Ending

Hi folks! I'm new in this forum and in the UNIX-world too!! I've got a real problem: I have to read out datas like name and e-mail-adress from a Windows- Server from the active directory and put this information into a file. This file should be moved (or copied) on a Unix- Server... But I... (3 Replies)
Discussion started by: spikylina
3 Replies

10. UNIX for Dummies Questions & Answers

Meaning of ; in UNIX file?

Hello. I'm looking at a file that has a ; at the beginning of certain lines. Could someone please tell me what that means? Is it a comment? Is it an execute? Thank You (1 Reply)
Discussion started by: willdaw3
1 Replies
Login or Register to Ask a Question