1
有一個在Shell腳本一個工具,它顯示的菜單中心,並做運行腳本,而一些task.I得到這個錯誤:算術語法錯誤
\007
In center function
COLUMNS : columns 142
2 : 13
/ShellsAndSQLs/task_menu: line 80: (columns 142 - 13)/2 : arithmetic syntax error
此代碼是從Solaris ENV複製其中回聲$柱(爲什麼?)是空白的價值。當複製到紅帽信封節目回聲$的列142(因爲它應該在全屏幕)。這裏是代碼的培訓相關部分:
#!/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
}
由於COLUMNS不爲空,我知道它不會進入if條件。同樣,COLUMNS可能會因s在window.How的IZE做我做
n=$((($COLUMNS - ${#2})/2))
工作?
使用COLUMNS = $(tput cols)而不是awk構造。 – 2012-07-14 19:38:24