$$number in the shell or shellscript


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users $$number in the shell or shellscript
# 1  
Old 10-08-2011
$$number in the shell or shellscript

What does $$number in the shell or shellscript do? Something like this where they use $$3 and $$1.

Managing projects with GNU make - Robert Mecklenburg, Robert William Mecklenburg, Andrew Oram - Google Books
# 2  
Old 10-08-2011
Quote:
What does $$number in the shell or shellscript do?
Nothing. It's a make's construction.
# 3  
Old 10-08-2011
Quote:
Originally Posted by yazu
Nothing. It's a make's construction.
What does that mean?
# 4  
Old 10-08-2011
Make gets to $ characters first and does its own substitution. If you want a real $ character to make it into the shell, you have to double it, $$.

Of course, you don't want the shell substituting it either here! That's why it's in single-quotes. It goes through make, turning '$$1' into '$1', passes through the shell, turning '$1' into $1, then awk sees the $1 and understands it as 'the first field'.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 10-09-2011
CPU & Memory

Using $$variablename is useful in indirect reference
I'm finding it hard to put into words, but consider this example:

Suppose you want to find last command line argument, how can you find it?

Code:
[root@localhost ~]# echo $#
3
[root@localhost ~]# echo $3
file3

But with indirect reference you can directly get it.

Code:
[root@localhost ~]# eval echo "\$$#"
file3

Newer bash also support's following format.

Code:
[root@localhost ~]# echo "${!#}"
file3

For more scripts and articles, check bellow link.

http://www.bashscript.blogspot.com/

Last edited by radoulov; 10-09-2011 at 07:48 AM.. Reason: Code tags!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Squence number manipulation in Shell

Hello Forum, I am receiving a file daily like ASAD but at the end there is a counter like 0012 (4 digits) so my every next file +1 I want to write a control script and check the last sequence number.Let's say If I receive a file ASAD0012 then after receiving this file I wan to say that... (5 Replies)
Discussion started by: cemokam65
5 Replies

2. Shell Programming and Scripting

Get the line number in shell script

I have one text file 1 2 3 a 5 4 4 3 where i want to print the line number while read line do line_no=`awk '{print NR, $0}'` echo 'In line no $line_no' done <$txt_file If i run the above code, it will print 'In line no 1 1 2 3' It prints the line number with the whole... (3 Replies)
Discussion started by: RJG
3 Replies

3. Shell Programming and Scripting

how to specify number of argument in shell

Hi I am new in shell, I am trying to create a small script that can do exit if a script is executed when argument not 2 #!/bin/sh if ; then echo greater exit 1; elif ; then echo less exit 1; fiit keeps returning me whatever number of argument I... (1 Reply)
Discussion started by: peuceul
1 Replies

4. Shell Programming and Scripting

calling 'n' number of shell scripts based on dependency in one shell script.

Hello gurus, I have three korn shell script 3.1, 3.2, 3.3. I would like to call three shell script in one shell script. i m looking for something like this call 3.1; If 3.1 = "complete" then call 3.2; if 3.2 = ''COMPlete" then call 3.3; else exit The... (1 Reply)
Discussion started by: shashi369
1 Replies

5. UNIX for Dummies Questions & Answers

A perfect number shell program

Here's my work of testing whether a number input is perfect or not.. echo Enter a number read no i=1 ans=0 while do if then ans='expr $ans + $i' fi i='expr $i + 1' done if then echo $no is perfect else echo $no is NOT perfect fi (12 Replies)
Discussion started by: Cyansnow
12 Replies

6. Shell Programming and Scripting

read number of arguments in c shell

I am writing script in c shell and using this script to read the command line arguments, but it is not working. Pl. someone let me know what is the problem. #!/bin/csh -f if ($#argv <> 2) then echo "you must give exactly two parameters" else set name1 = $argv ... (1 Reply)
Discussion started by: skumar11
1 Replies

7. Shell Programming and Scripting

shell magic number with a -

In one of our internal scripts (unix.run), I have noticed that the following shebang. #!/bin/sh - for i in test1 test2 test3 ; do . . . Any idea what the - in the magic number stands for ? And what impact does it have on the script ? Continuing on the same script, I have the... (3 Replies)
Discussion started by: vino
3 Replies

8. Shell Programming and Scripting

Number of parameters to a shell script

Is there any restriction on number of parameters can be passed on to the shell script? I found, after 9th parameter for parameter 10, it is taking parameter 1. (1 Reply)
Discussion started by: videsh77
1 Replies

9. Shell Programming and Scripting

C-shell command to get system IP number?

Is there a C shell command (or script anyone knows of) that will return the IP number of the system? I know that 'hostname' returns the host name, but I need the IP number, and I cannot assume access to 'nslookup'. :confused: (2 Replies)
Discussion started by: Splatt
2 Replies

10. Shell Programming and Scripting

shell to number and to string

Hello Does the unix korn shell provide a function to convert between number and string data-types regards Hrishy (1 Reply)
Discussion started by: xiamin
1 Replies
Login or Register to Ask a Question