help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] how to understand the xargs


From: Greg Wooledge
Subject: Re: [Help-bash] how to understand the xargs
Date: Tue, 27 Dec 2011 10:40:19 -0500
User-agent: Mutt/1.4.2.3i

On Tue, Dec 27, 2011 at 11:35:22PM +0800, lina wrote:
> On Tuesday 27,December,2011 11:31 PM, Greg Wooledge wrote:
> >>On Tuesday 27,December,2011 11:16 PM, Greg Wooledge wrote:
> >>>   i=$((i+1))
> >On Tue, Dec 27, 2011 at 11:27:35PM +0800, lina wrote:
> >>     i=$(i+1)
> >$(...) is command substitution.
> >$((...)) is arithmetic substitution.
> This is a core part,
> 
> well, why not it showed me nothing,
> 
> after run it?

Command substitution means you run the thing inside $(...) as a command,
and then use its output.

  $ i=3
  $ echo $(i+1)
  bash: i+1: command not found

  $ 

In this case, it tries to run i+1 as a command (which generates an error).
Then it takes the standard output of that command, word splits it, and
passes the results to echo.  Since the i+1 command did not produce any
standard output (it only produced errors), echo receives no arguments,
so it writes a blank line.

Arithmetic substitution is COMPLETELY different:

  $ i=3
  $ echo $((i+1))
  4
  $ 

i=$((i+1)) is how you add 1 to the variable named i in /bin/sh.  There
are other ways in bash, but i=$((i+1)) will work in both sh *and* bash,
so you should learn that one first.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]