Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8220647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:36:01+00:00 2026-06-07T13:36:01+00:00

There is a tool in Shell Script which Displays the menu in center and

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:36:06+00:00Added an answer on June 7, 2026 at 1:36 pm

    Your echo and your error message seem to hold the clue:

    COLUMNS : columns 142
    

    and

    /ShellsAndSQLs/task_menu: line 80:  (columns 142 - 13) / 2 : arithmetic syntax error
    

    Where does “columns” (all lower-case) come from? Somehow your variable is getting some text added to it.

    That doesn’t happen for me in ksh and I don’t see where it’s happening in your script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a standalone tool, that can be ran from a shell script, to
Is there any tool or method that can speed up this process? For instance
Is there any tool which gives you the view of current execution of you
Is there any validation tool for shell scripting on unix platform. like after the
I use Emacs for shell scripts. I know I read somewhere there's some mode
Im searching a tool which allows me to specify some folders as bookmarks and
I was wondering if there is an off the shelf tool to help create
Is there any tool that analyse and reports number of functions (including member functions)
Is there a tool that will let you search a number of different crystal
Is there a tool in the market that takes Visual Studio nmake files, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.