Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a bash script which checks the available space on disk:

if [ check_space -gt "85" ]; then
echo "removing"
echo "not removing"

check_space returns a number like 52 and the check_space function is:

check_space() {
df /dev/sda1 | tail -1 | awk '{print $5}' | sed 's/%//';

It's returning ./ line 63: [: check_space: a full expression was expected (I translated it from spanish, so that maybe not exact translation). What could be wrong?

share|improve this question
Please re-run the script with LANG=C so that we get the exact error message. – womble Aug 23 '11 at 13:54
up vote 10 down vote accepted

Your condition isn't actually calling check_space, you need something like:

if [ `check_space` -gt "85" ]; then
share|improve this answer
@Ryan, no, this example works perfectly well. – glenn jackman Aug 23 '11 at 15:41
You're absolutely right. I'll remove my false doctrine. – Safado Aug 23 '11 at 16:05

Here's how you can do it...


CHECK_SPACE=`df /dev/sda1 | tail -1 | awk '{print $5}' | sed 's/%//'`;

if [ $CHECK_SPACE -gt "85" ]; then
echo "removing"
echo "not removing"

I had to pull out my bash cheat sheet. Functions in bash can't return a value, only an exit status.

share|improve this answer
Usually, you write the function to print information to stdout, and then capture the output when you invoke the function: space=$(check_space) – glenn jackman Aug 23 '11 at 15:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.