Putting $$ before filename


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Putting $$ before filename
# 1  
Old 02-20-2014
Putting $$ before filename

Hello ,

I am searching a directory for a file and have to assign the filename to a variable .
The variable must have form $$filename

So my code is

Code:
 echo "'$$filename='`ls -lrt *PreMatch*.csv| head -1 | nawk '{print $9}'`"

however $$ is converting to a number .
How could I make it $$ only

o/p coming as

Code:
'3670506filename='file.csv

Code:
I want it as $$filename = file.csv

# 2  
Old 02-20-2014
Try:
Code:
printf '$$filename = %s\n' "$(ls -rt *PreMatch*.csv | head -1)"

Note that this just prints a line of output; it does not assign anything to any shell variable. (And, note that $$filename is not a valid shell variable name.)
# 3  
Old 02-20-2014
The problem - save for what Don Cragun already explained - "$$" is short for "the PID of the current process" and interpreted by the shell that way. YOu can test that with the following script:

Code:
#! /bin/sh
echo $$
sleep 9999999
exit 0

Start this script and from another terminal do:

Code:
ps -fp <PID>

substituting "<PID>" with the displayed number. You will see that the shell process has exactly this process number. (Stop the script with "CTRL-C" afterwards.)

So, even if you would manage to assign the value to such an ill-named variable you would have no possibility to retrieve it from there because any time you write "$$" it will be translated to the PID. If you want to simply have the "$$" in the output you can use "\" to escape the "$":

Code:
echo "\$\$filename"

I hope this helps.

bakunin

Last edited by bakunin; 02-20-2014 at 06:15 AM..
# 4  
Old 02-20-2014
I suspect they were using $$ to get a unique random number for a temporary file, so that if you ran two of the same script, they wouldn't stomp on the same file...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Hardware

Putting an old hd in a new computer

What are the steps you need to take when you put an old HD in a new computer? I just did this. Every time it makes it to the windows boot screen then restarts. I have a bunch of old engineering software that is not compatible with the newer versions of windows. I figured this out after I bought... (6 Replies)
Discussion started by: cokedude
6 Replies

2. Shell Programming and Scripting

Other way aside from putting more PIPES (|)

I already manage to get the output that i want.. but wat if removing all the pipes and convert it 1 liner with less pipes. My command below can get the ouput that i want. i just want to remove the pipes or less pipes. #cat file1 us-west-2a running i-3397a421... (2 Replies)
Discussion started by: kenshinhimura
2 Replies

3. Programming

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My code: if then set "subscriber" "promplan" "mapping" "dedicatedaccount" "faflistSub" "faflistAcc" "accumulator"\ "pam_account"; for i in 1 2 3 4 5 6 7 8;... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

4. UNIX for Dummies Questions & Answers

to extract all the part of the filename before a particular word in the filename

Hi All, Thanks in Advance I am working on a shell script. I need some assistance. My Requirement: 1) There are some set of files in a directory like given below OTP_UFSC_20120530000000_acc.csv OTP_UFSC_20120530000000_faf.csv OTP_UFSC_20120530000000_prom.csv... (0 Replies)
Discussion started by: aealexanderraj
0 Replies

5. Shell Programming and Scripting

putting two images together

Hi, I generated many figures in .png format (approximately 120). Right now I need to pair the figures on a single page so that the files with the same file name (i.e. jack) that end with .matrix.png are placed on the left and .cdt.png is on the right (so jack.matrix.png with jack.cdt.png... (6 Replies)
Discussion started by: kylle345
6 Replies

6. Shell Programming and Scripting

Need help putting output on one line

Good afternoon, I have been searching the web, and these forums for help. I will try my best to explain the issue, and what my desired results are. I am doing queries in MYSQL, and need the output to be sent to a file. That file needs to have things with the same ID on the same line. To... (14 Replies)
Discussion started by: brianjb
14 Replies

7. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

8. Shell Programming and Scripting

joining multiple files into one while putting the filename in the file

Hello, I know how to join multiple files using the cat function. I want to do something a little more advanced. Basically I want to put the filename in the first column... One thing to note is that the file is tab delimited. e.g. file1.txt joe 1 4 5 6 7 3 manny 2 3 4 5 6 7 ... (4 Replies)
Discussion started by: phil_heath
4 Replies

9. Shell Programming and Scripting

gzcat into awk and then change FILENAME and process new FILENAME

I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part... (6 Replies)
Discussion started by: timj123
6 Replies

10. UNIX for Dummies Questions & Answers

Putting pC on network

How do I put a my PC with linux 7.0 on a class B network. Can someone give me info or text that will guide me? (1 Reply)
Discussion started by: Rush
1 Replies
Login or Register to Ask a Question