Basic help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Basic help
# 1  
Old 08-24-2015
Basic help

Hi ,

I need to know the difference between $((command)) and $(command) and $(($(command))).
"" and '' and ``.
I have tried searching the help files but cant able to find this.
Could you let me knoq about any document.

Thanks
# 2  
Old 08-24-2015
You need to supply additional info on e.g. OS, shell, that you use. Assuming bash:
- the first expression will try to apply "arithmetic expansion" and assume command to be a variable and expand it (presumedly to zero).
- the second is a "command substitution" and expand to command's stdout in lieu of the command name.
- the third construct will apply comand substitution and then arithmetic expansion, so make sure the command sub. will yield an integer value.
All this can be found in the man page of your shell.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 08-24-2015
Spaces can visualize where the tokens end.
For example:
Code:
x=1; echo "$(( x + 1 ))"
echo "$( ls )"
echo "$(( $( wc -l </etc/passwd ) + 1 ))"

All echo arguments are in "quotes", where $var and $( ) and $(( )) are evaluated.
But not in 'ticks', for example
Code:
echo '$( ls )'

And see what an unquoted
Code:
echo $( ls )

does!
The "quotes" are mostly used in command arguments; they evaluate $ as shown but not special characters like *.
An assignment like
Code:
x="$(( x + 1 ))"

does not need quotes, because the right side is not a command argument.
For quotes within quotes, one can sometimes choose the different quote types.
Code:
echo 'a part with "double-quote" within single-quotes'
echo "a part with 'single-quote' within double-quotes"

Or use a \ single-character quoting, preferably outside the quoted strings, using a simple string concatenation.
Code:
echo 'a part with '\''single-quotes'\'' withing single-quotes'
echo "a part with "\""double-quotes"\"" withing single-quotes"

This User Gave Thanks to MadeInGermany For This Post:
# 4  
Old 08-24-2015
Most has already been said, but:

`command` and $(command) does basically the same. It executes "command" and uses the output of this command to complete the command line. "command" could either be a single command or even a series of commands, a pipeline, etc..

Example:

Code:
command1 $(command2)

will first execute "command2", then put its output onto the commandline and execute the resulting line. Suppose the output to be "hello world" the shell would try to execute

Code:
command1 "hello world"

after completing "command2". The mechanism is called "process substitution".

The first variant is deprecated, has a lot of shortcomings and should be avoided. Use the second variant instead whenever possible.

Only very old shells (the original Bourne shell for instance) support the first variant(called "backticks") only. Modern shells (ksh, ksh93, bash, ...) support both variants but the former only for backwards compatibility.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
# 5  
Old 08-25-2015
@bakunin: Sorry to disagree, but above is called "command substitution". man bash:
Quote:
Command substitution allows the output of a command to replace the command name. There are two forms:

$(command)
or
`command`
Process substitution takes a different form:
Quote:
Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming open files. It takes the form of <(list) or >(list).
This User Gave Thanks to RudiC For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. What is on Your Mind?

Vs basic

There isn't much of a relation between 80's BASIC and today's BASIC. A lot of languages seem similar. The BASIC I worked with was Dartmouth or VSBASIC. Now existing as ATARI BASIC. PERL and JULIA look appealing, it would be nice if there where a program like VSBASIC. 80's... (7 Replies)
Discussion started by: teak
7 Replies

2. Solaris

Basic - how do I?

How do I use ls and grep together to count a certain number of files in a directory? -Thanks (1 Reply)
Discussion started by: secno
1 Replies

3. UNIX for Dummies Questions & Answers

basic if else

I know this is pretty basic, but i cant figure it out to save my life. i want it to ask for a variable, as long as that variable isnt -/0 i want it to print out the area. else if the variable is -/0, i want it to print out invalid entry. the only problem is it will still try to print out the... (1 Reply)
Discussion started by: cookiebooy
1 Replies

4. HP-UX

to know the basic

Hi, Good morning I want to install HP-Unix in my PC. I already have windows XP home edition in my PC. I do not want remove XP,But I need HP-Unix in the same system. Is it posssible? If it is what is the name and version of HP-Unix cd? Where can I get the CD to install. I have... (4 Replies)
Discussion started by: nandhini
4 Replies

5. UNIX for Dummies Questions & Answers

Need some basic help

Hi everyone, I need some help! I know that this is a very simple little problem but I seem to be stuck. I was just wondering if you could show me the right way. I basicly have to write a single line of commands (using piping) to do the following: From the file data.txt, select all of the... (2 Replies)
Discussion started by: itk
2 Replies

6. HP-UX

Bt-basic

Hi Guys, I very new to bt-basic even I got 8 years experience on UNIX. I searched through google about bt-basic but nothing really give me solid documentation. Anybody have documentation or manual for this bt-basic? Pls help me (2 Replies)
Discussion started by: shahru
2 Replies

7. What is on Your Mind?

Basic...

hi, I am pretty new both to unix and this forum, can anyone help me to give shortcuts to my commands... eg:- instead of "cd /usr/bin" i want to to give " bin " and get to that path. I'm using HP-UX 11.0 abey (2 Replies)
Discussion started by: abey
2 Replies

8. UNIX for Dummies Questions & Answers

Basic

hi, I am pretty new both to unix and this forum, can anyone help me to give shortcuts to my commands... eg:- instead of "cd /usr/bin" i want to to give " bin " and get to that path. I'm using HP-UX 11.0 abey (2 Replies)
Discussion started by: abey
2 Replies
Login or Register to Ask a Question