-3

Possible Duplicate:
bash store output as a variable

I have a script that outputs a simple integer like "10", then i have a second script where i want to call this script and grab the integer as a variable.

#!/bin/bash

KBPS= ## NEED OUTPUT FROM /USR/LOCAL/BIN/ETH0TX.SH
THRESHOLD=50 #KBPS
if [ $KBPS -gt $THRESHOLD ]; then
   exit 1
fi

Is that possible?

3
  • i tried various combinations some very similar to the solution. do i need to list everything that didn't work? Commented Jan 4, 2013 at 12:49
  • Yes, mostly if already purposed answer did'nt make your job! Commented Jan 4, 2013 at 12:50
  • i think its perfectly acceptable to ask a simple question, get a simple answer without posting inaccurate code. But in a lot of cases i agree you should show your work. Commented Jan 4, 2013 at 13:05

4 Answers 4

0

Like this:

KBPS=$(/usr/local/bin/eth0tx.sh)
Sign up to request clarification or add additional context in comments.

1 Comment

thanks everyone! first answer wins
0
KBPS=$(/usr/local/bin/eth0tx.sh)

will set KBPS to the output of your script. Capitalisation removed. You can check the exit code with $?. That may be worth doing rather than simply populate KBPS with invalid/blank data.

More info here, and note the comments re. whitespace/newlines etc.

Comments

0

Yes it is:

KBPS=$(theotherbashscript)

This is called command substitution.

Note: requires that the output does not contain spaces.

1 Comment

If you're worried about spaces, you can quote the string that you're capturing via command substitution: KBPS="$(theotherbashscript)".
0

KBPS=$(/usr/local/bin/eth0tx.sh)

What a race! :D

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.