You can define a function using the following syntax:
foo(){Now you can call the function foo() using the echo statement as follows:
date
}
echo "Today is $(foo)"Sample outputs:
Today is Sat Jan 22 00:27:26 IST 2011A sample shell script to display system info:
#!/bin/bash
findcpu(){
grep 'model name' /proc/cpuinfo | uniq | awk -F':' '{ print $2}'
}
findkernelversion(){
uname -mrs
}
totalmem(){
grep -i 'memtotal' /proc/meminfo | awk -F':' '{ print $2}'
}
echo "CPU Type : $(findcpu)"
echo "Kernel version : $(findkernelversion)"
echo "Total memory : $(totalmem)"
No comments:
Post a Comment