Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if bc command is available #1201

Merged
merged 2 commits into from
Sep 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions quickstart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,15 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then
echo "ERR: Sorry this is working only on x86_64!"
exit 1
fi

echo " : --- Memory, CPU info ---- "
mem=$( grep MemTotal /proc/meminfo | awk '{print $2}' | xargs -I {} echo "scale=4; {}/1024^2" | bc )
echo "System memory (GB): ${mem}"
if [ -n "$(command -v bc)" ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, i have always used which, but i guess command is a more recommended way? (saw a comment about it, but don't have an authoritative source). Either works. Why do you use -v though?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know which of the commands would be better. I don't know which and i get command -v from an stackoverflow answer.

But i can verfiy that -v is good because it displays only the path of the program or blank. Without -v it displays an explanation of the program, which needs more time to display and it can happen that a program has no description, so it would be return blank too.

mem=$( grep MemTotal /proc/meminfo | awk '{print $2}' | xargs -I {} echo "scale=4; {}/1024^2" | bc )
echo "System memory (GB): ${mem}"
else
mem=$( grep MemTotal /proc/meminfo | awk '{print $2}')
echo "System memory (KB): ${mem}"
fi
grep SwapTotal /proc/meminfo
echo "CPU number: $(grep -c processor /proc/cpuinfo) x $(grep "bogomips" /proc/cpuinfo | head -1)"
grep Free /proc/meminfo
Expand Down