Bash – How to combine bash arithmetic with command output

bashdate

Suppose you had two commands:

First command

let foo=2+2
echo $foo
4

Second command

date "%s"
1377107324

How would you combine them?


Attempt 1.

echo The epoch time is: `date +%s` in 100 seconds the time \
     will be: `let future={date +%s}+100` $future

Attempt 2.

echo The epoch time is: `date +%s` in 100 seconds the time \
     will be: `let future=(date +%s)+100` $future

Plus about 30 other similar attempts

Best Answer

This is an important reason to use the $( ) instead of ` ` (see What's the difference between $(stuff) and `stuff`?)

If you nest it like this, you don't even need let or a variable:

$ echo $(date +%s) " "  $(( $(date +%s)+100 ))
1377110185   1377110285
Related Question