0

I'm trying to write a script to keep track of my system information. I want to use "function" in the script and just call the functions out. I'm having trouble with the commands working in the function. Obviously they are written incorrectly.

#!/bin/bash

#function definition

function report_system_uptime()
{
echo $(($uptime))
}
function report_drive_space()
{
echo $(($df))
}
function report_home_space()
{
echo $(($du /home/* | sort -nr))
}

#Call the function
report_system_uptime
report_drive_space
report_home_space
1
  • 2
    Why so complicated? You can just call the binaries, like uptime, du /home, etc.
    – Marco
    Commented Nov 25, 2015 at 16:24

1 Answer 1

1

You can call the command. There's no need to echo them.

Example:

echo $(df -h)

Just call:

df -h

Another thing. Don't use $((..)). This is used to math in bash:

$ echo $((1+1))
2
$ echo $((df -h))
0
2
  • Thanks for pointing out my errors. I didn't realize $((...)) was exclusively for math. So much to remember when writing a shell script. I guess I over analyze it.
    – user144380
    Commented Nov 25, 2015 at 16:53
  • No problem... We live, we learn :) Commented Nov 25, 2015 at 19:15

You must log in to answer this question.