The difference between $(command) and `command`


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting The difference between $(command) and `command`
# 1  
Old 03-08-2007
The difference between $(command) and `command`

In the for loop, we always write like
for CurUser in $( cut -f 1 -d : /etc/passwd )
do
...
done
or
for CurUser in `cut -f 1 -d : /etc/passwd`
do
...
done
Is there any difference between them ?
thanks !
# 2  
Old 03-08-2007
The `backticks` syntax is the old style command substitution which does not allow nesting.
# 3  
Old 03-08-2007
Quote:
Originally Posted by Ygor
The `backticks` syntax is the old style command substitution which does not allow nesting.
It does allow nesting, but the inner backticks must be escaped.
# 4  
Old 03-08-2007
Quote:
Originally Posted by bluepluto
In the for loop, we always write like
for CurUser in $( cut -f 1 -d : /etc/passwd )
do
...
done
or
for CurUser in `cut -f 1 -d : /etc/passwd`
do
...
done
Is there any difference between them ?
thanks !
The backtick version can be used in all Bourne-type shells; the other works in all POSIX shells (ksh, bash, etc.).

It is easier to nest the second version; if you nest backticked substitution, you have to escape the inner backticks.

You should also note that that is almost always the wrong way to read a file (not to mention the useless use of cat):

Code:
while IFS=: read CurUser junk
do
   ...
done < /etc/passwd

# 5  
Old 03-09-2007
Quote:
Originally Posted by cfajohnson
It does allow nesting, but the inner backticks must be escaped.
I was of the notion, nesting of backticks is not possible,

as said escaping the inner backticks worked,

Code:
head `ls -1 \`echo "abhead"  |sed 's/^..//'\``

Thanks! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

What is the difference in this two awk command?

What is the difference in these two awk command? Both returns same output but I am not sure what is the use of +0 in command 1. awk -F "," '{print $1+0,$2+0,$3+0}' awk -F "," '{print $1, $2, $3}' (3 Replies)
Discussion started by: later_troy
3 Replies

2. UNIX for Dummies Questions & Answers

Explain difference of tar command

Hello All, I have been seeing a weird(at least for me, at this point) issue with a specific tar command. 1st fashion) Normally, if i have to tar anything at the command line I tend to use tar -cvzf <tar-file_name.tgz> <directory_to_be_tarred> this command works perfectly fine with out... (1 Reply)
Discussion started by: getnetha
1 Replies

3. Solaris

Difference between fuser and lsof command

Hi, Can anyone explain me the difference between fsuer and lsof commands. As per my knowledge both the commands are used to find the processes used by the current file system or user. Apart from that what is the major difference between these commands (3 Replies)
Discussion started by: rogerben
3 Replies

4. Shell Programming and Scripting

What's the difference between print and printf in command?

For example, in this command: ls /etc/rc0.d/ -print ls /etc/rc0.d/ -printfThe outputs are quite different, why? (7 Replies)
Discussion started by: Henryyy
7 Replies

5. UNIX for Dummies Questions & Answers

command difference - find

Hi, What is the difference between these two? find /some_dir -type f -exec chmod 070 {} \; and chmod 070 `find /some_dir -type f` Thanks (5 Replies)
Discussion started by: lamont
5 Replies

6. UNIX for Dummies Questions & Answers

which command difference

What is the difference between (unix-system “which ) and which commands. For example when I use the (unix-system “which visual_elite) command I get the following result: /home/vhdl/edatools/mentor/visualelite/VisualElite-4.2.1/Linux2.4/bin/visual_elite When I do the same on... (1 Reply)
Discussion started by: mihaelab
1 Replies

7. UNIX for Dummies Questions & Answers

Difference in command syntax different shells

hi, i am aa unix amateur and i am using tsh, csh and bash most of the time. i have been looking over the net to find a summary of the differences in command syntax for example: in csh and tsh you do alias whatday date while in bash and ksh you do alias whatday=date i just want more... (2 Replies)
Discussion started by: hobiwhenuknowme
2 Replies

8. Programming

Difference between cp and mv linux command

Hi, I am facing one problem only with mv command not with cp command. I have a test program #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/mount.h> #include <fcntl.h> #include <errno.h> int sync_file(char *file) { FILE *fp=NULL;... (6 Replies)
Discussion started by: dharshini123
6 Replies

9. Solaris

difference between pkginfo and pkgchk command

can anyone explain me the difference between pkginfo and pkgchk command in solaris. Both are used to display the package details, then what is the difference between both. (5 Replies)
Discussion started by: rogerben
5 Replies

10. AIX

difference between ls -b and ls command

hi anyone please tell me what is the difference between ls -b command and ls command. (1 Reply)
Discussion started by: sathish2win
1 Replies
Login or Register to Ask a Question

Featured Tech Videos