Sure this is just some basic scripting 101 snafu, but I'm at a loss.
I am basically building a library, and this piece if becoming a real pain--
function get_current_space () {
echo $*
for check_space in $*
do
check_var=`echo $check_space | sed 's/\//\_/g'`
part$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $1}'`
size$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $2}'`
used$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $3}'`
avai$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $4}'`
perc$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $5}'`
moun$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $6}'`
done
}
this is the output from calling the function with just /boot
mytest.sh: line 7: part_boot=/dev/sda1: No such file or directory
mytest.sh: line 8: size_boot=251M: command not found
mytest.sh: line 9: used_boot=16M: command not found
mytest.sh: line 10: avai_boot=223M: command not found
mytest.sh: line 11: perc_boot=7%: command not found
mytest.sh: line 12: moun_boot=/boot: No such file or directory
I can drop set in front of the variables, and that makes it a variable, but of course won't pass the variable back.
Any help?
I am basically building a library, and this piece if becoming a real pain--
function get_current_space () {
echo $*
for check_space in $*
do
check_var=`echo $check_space | sed 's/\//\_/g'`
part$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $1}'`
size$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $2}'`
used$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $3}'`
avai$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $4}'`
perc$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $5}'`
moun$check_var=`df -h | grep "$check_space" | grep -v "$check_space"[a-zA-Z0-9] | awk '{print $6}'`
done
}
this is the output from calling the function with just /boot
mytest.sh: line 7: part_boot=/dev/sda1: No such file or directory
mytest.sh: line 8: size_boot=251M: command not found
mytest.sh: line 9: used_boot=16M: command not found
mytest.sh: line 10: avai_boot=223M: command not found
mytest.sh: line 11: perc_boot=7%: command not found
mytest.sh: line 12: moun_boot=/boot: No such file or directory
I can drop set in front of the variables, and that makes it a variable, but of course won't pass the variable back.
Any help?