Solved

Linux: Add Strings

Posted on 2013-11-15
3
176 Views
Last Modified: 2013-11-15
How can I add x and y?  This does not work:
x=1;y=2;echo $x+$y

Open in new window

0
Comment
Question by:hankknight
  • 2
3 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 400 total points
ID: 39651054
POSIX format:

echo $((x+y))

The old "expr" style:

echo `expr $x + $y`

Using the calculator "bc":

 echo "$x + $y" | bc
0
 
LVL 13

Assisted Solution

by:duncanb7
duncanb7 earned 100 total points
ID: 39651056
x=1
y=2

echo $((x+y))

it should be with $(( ...))
0
 
LVL 13

Expert Comment

by:duncanb7
ID: 39651066
woolmilkporc, you are faster than me in 17 seconds to get the final answer,
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question