There is a tool in Shell Script which Displays the menu in center and do some task.I get this error while running the script :
\007
In center function
COLUMNS : columns 142
2 : 13
/ShellsAndSQLs/task_menu: line 80: (columns 142 - 13) / 2 : arithmetic syntax error
This code was copied from solaris env where echo $COLUMNS(why??) show blank value.This when copied to Redhat Env shows echo $COLUMNS as 142(as it should in full screen).Here is the relevent section of the code :
#!/bin/ksh
trap "tput sgr0; tput clear;" 1 2 3 4 5 6 7 8 10 11 12 13 14 15
if [ $# -ne 2 ]
then
echo "Wrong parameters specified" >&2
exit 1
fi
if [ "$COLUMNS" = "" ]
then
echo "column in if"
stty -a |
awk -F \; '/columns/ { for (i = 1; i <= NF; i++) {
if ($i ~ "columns") {
sub(" *columns *= *", "", $i);
print $i;
exit
}
}
}' |
read COLUMNS
fi
center()
{
echo "In center function"
echo "COLUMNS : $COLUMNS"
echo "2 : ${#2}"
n=$(( ($COLUMNS - ${#2}) / 2 ))
#n=`expr $COLUMNS - ${#2} / 2`;
echo "n is $n";
echo "COLUMNS in center fun : $COLUMNS" ;
tput cup $1 $n
echo $_N $2 $_C
}
I know that it is not going in the if condition as the COLUMNS is not blank.Also COLUMNS may vary depending on the size of the window.How do i make the
n=$(( ($COLUMNS - ${#2}) / 2 ))
Work?