Home > OS >  Unexpected Argument expr & MemTotal
Unexpected Argument expr & MemTotal

Time:01-27

Attempting to get this little bash script working and I am currently receiving this error:

Not sure where my syntax issue is.

expr: syntax error: unexpected argument ‘32489356’
Your System RAM is: $RAM_GB GB and that meets the minimum requirements for Docker Desktop.
#!/bin/bash
CURRENT_TIME="$(date  "%x %r %Z")"
TIMESTAMP="Generated $CURRENT_TIME, by $USER"
echo $TIMESTAMP


check_ram () {
  RAM_KB=$(grep MemTotal /proc/meminfo)
  RAM_GB=$(expr $RAM_KB / 1000000)
  if ($RAM_GB > 4); then
  echo 'Your System RAM is: $RAM_GB GB and that meets the minimum requirements for Docker Desktop.'
  else
  echo 'Your computer does not meet the minimum RAM requirements.'
  exit 0
  fi
  return
}

CodePudding user response:

Here is a fix

#!/bin/bash
CURRENT_TIME="$(date  "%x %r %Z")"
TIMESTAMP="Generated $CURRENT_TIME, by $USER"
echo $TIMESTAMP

check_ram () {
RAM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}')
RAM_GB=$(expr $RAM_KB / 1000000)
if [ $RAM_GB -gt 4 ]; then
echo "Your System RAM is: $RAM_GB GB and that meets the minimum requirements for Docker Desktop."
else
echo "Your computer does not meet the minimum RAM requirements."
exit 0
fi
return
}
  •  Tags:  
  • bash
  • Related