I'm working on shell script and trying to split user input into multiple variable and use them at different places.
User input is not fixed so can't really assign fixed number of variable, input is separated by comma ,
./user_input.ksh -string /m01,/m02,/m03
#!/bin/ksh
STR=$2
function showMounts {
echo "$STR"
arr=($(tr ',' ' ' <<< "$STR"))
printf "%s\n" "$(arr[@]}"
for x in "$(arr[@]}"
do
free_space=`df -h "$x" | grep -v "Avail" | awk '{print $4}'`
echo "$x": free_space "$free_space"
done
#total_free_space = <total of $free_space>
#echo "$total_free_space"
}
Basically $STR* variable value is filesystem mount points
Host output if run separate df -h
command
$ df -h /m01 | grep -v "Avail" | awk '{print $4}'
***Output***
150
Current problems:
(working)1. How to get free space available for each /m* using df -h?
A variation on the theme:
Which gives you:
Hope that helps..
--ab1
Easiest thing to do is to use shell array here like this:
Output:
To read elements individually you can use:
Update: Here is your corrected script:
Don't use all-upper-case for variable names unless you are going to export them (by convention and to avoid clashes with built in names like HOME, PATH, IFS, etc.).
For your overall script, you should simply be doing something like this:
depending on what your
df -h
output looks like and what you're final output is supposed to be.you can try,
you get: