Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting dynamic variable in a function

Status
Not open for further replies.

tekinept

MIS
Oct 22, 2002
24
US
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?
 
In your shell man page pay attention to the eval builtin command.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yep, that did the trick. Still wondering why it interpreted as a command rather than a var.... Guessing it has to do with the why I am assigning it...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top