0

I'm trying to save in CORE_NUMBER the number of cores of my pc. I've tried with:

system_info.sh

#!/bin/bash
cd /proc
CORE_NUMBER= cat cpuinfo | grep processor | wc -l
#...

So that I can do something like:

compile.sh

#!/bin/bash
set -e
../system_info.sh
mkdir -p build && cd build
cmake ..
make -j$CORE_NUMBER
#...

When running ../system_info.sh, the number of cores is (logically) shown in the terminal.

How can I avoid that, and just assign it to CORE_NUMBER?

Thanks in advance,

Eduardo

eduherminio
  • 1,514
  • 1
  • 15
  • 31

1 Answers1

1

In your system_info.sh, you should use backtick to execute the command, and assign the output to variable CORE_NUMBER

CORE_NUMBER=`cat /proc/cpuinfo | grep processor | wc -l`

example use:

sharuzzaman@mylaptop ~
$ export CORE_NUMBER=`cat /proc/cpuinfo |grep processor |wc -l`

sharuzzaman@mylaptop ~
$ echo $CORE_NUMBER
4
Sharuzzaman Ahmat Raslan
  • 1,557
  • 2
  • 22
  • 34