andrew andrew - 2 months ago 10
Linux Question

Concatenate two instructions in bash script

I would like to make program with option -j after checking how many cores cpu has got.

#!/bin/bash
x="grep -c ^processor /proc/cpuinfo"
make -j${x}


x variable display number of cores. make -j${x} not working

Answer

You'll want to capture the output of the command into a string through a subshell:

#!/bin/bash
x=$(grep -c ^processor /proc/cpuinfo)
make -j"${x}"