ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello, just one more question and I'm hoping someone can help me as I know it's simple for someone more experienced. How do I add these two variables to make it equal "0". For example, I need the sum of $CNT1 and $CNT2. I kinda giot screwed up towards the bottom of the script.
It seems lots of people keep directing you so sites but it does not appear you are reading many / any of them. Bash arithmetic can be performed with expr, let or (()).
I will leave it up to you to work out which you prefer.
It seems lots of people keep directing you so sites but it does not appear you are reading many / any of them. Bash arithmetic can be performed with expr, let or (()).
I will leave it up to you to work out which you prefer.
I'm not sure which sites you are referring to and I have been going to many of them to save myself from asking people for help, but I will try and do this on my own from now on.
That just printed out the existing PID id's. What I am looking for is adding both $CNT1 and $CNT2 together. I have to have just one value for output.
If you're getting integers for $PID1 and $PID2 then your ps -ef shows something completely different than mine. My ps doesn't support the command-line format you use when setting CNT1 and CNT2, either. At this point I think you need to go through man ps and assemble what you need a step at a time in the terminal.
Kevin Barry
You can add the values together using commands like expr or bc (expr doesn't work for very large numbers or do floating point so bc is sometimes used when expr doesn't work.
Code:
TTLCNT=$(expr $CNT1 + $CNT2)
echo $TTLCNT
--OR--
Code:
TTLTCNT=$(echo $CNT1 + $CNT2 | bc)
echo $TTLCNT
Note that for floating point you have to use "bc -l" instead of just bc.
Whenever someone mentions a command you can find out more about the command by typing "man <command>" and/or "info <command>".
The shells have a lot built into them so you can do math without requiring external commands but being an old UNIX Admin I tend to continue using the commands above.
You can add the values together using commands like expr or bc (expr doesn't work for very large numbers or do floating point so bc is sometimes used when expr doesn't work.
Code:
TTLCNT=$(expr $CNT1 + $CNT2)
echo $TTLCNT
--OR--
Code:
TTLTCNT=$(echo $CNT1 + $CNT2 | bc)
echo $TTLCNT
Note that for floating point you have to use "bc -l" instead of just bc.
Whenever someone mentions a command you can find out more about the command by typing "man <command>" and/or "info <command>".
The shells have a lot built into them so you can do math without requiring external commands but being an old UNIX Admin I tend to continue using the commands above.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.