Centering a line

So I am trying to use the .ce 3 command to center 3 lines in my text, but I am getting an execute permission denied. I made rwx capabilites for all users too. Any idea why I am getting this error?

Could you be more specific? Is this nroff? What are you executing? Why do you need execute permissions? Why do users need write access? what OS/version is this? Could you give an example and desired output?

I have a menu with three separate lines...

Phone Book
Company
Phone Number

I just want to center these three lines. I am in bsh. I do not know how to center these...

What is bsh? How is the .ce command used? Do not leave us guessing. Show a representative sample of input, desired output, attempts at a solution and specify what OS and versions being used, or this thread will be closed.

Bsh is my shell that I am using. I have a script that echoes 3 lines that I stated above. I researched how to center lines in unix and someone said tO use the .ce 3 command but it didn't wOrk. Is there another way to center lines in my script

Never heard of bsh. What's your system? what are you trying to center lines in? What is your script anyway?

I'm using bash. Sorry. All I want to know is if there is some generic command in vi editor to center a line???

:ce works in vim. Is your editor vim?

If you are trying to center output, take a look at this function. I don't know where I got it as it's been in my bag of tricks for ages. Works in ksh93 on Solaris.

$ cat print_centered.ksh
#!/usr/dt/bin/dtksh

print_centered(){
  integer screen_width=$(stty|grep columns|cut -f2 -d';'|cut -f2 -d'=')
  integer text_length=${#1}
  integer pad=$((($screen_width - $text_length)/2 ))
  format="%${pad}s%s"
  printf "$format\n" " " "$1"
}

print_centered "center this text please"

exit 0

$ print_centered.ksh
                            center this text please
$

I just have vi editor running....

---------- Post updated at 05:58 PM ---------- Previous update was at 12:09 PM ----------

gary...

when I run your script, it says `(' unexpected

Am I missing something?

What shell are you using?

bash shell

At the bash prompt...

$ cat file1
Phone Book
Company
Phone Number

$ COLUMNS=179

$ while read TEXT; do printf '%*s\n'  $(((($COLUMNS-${#TEXT})/2)+${#TEXT})) "$TEXT"; done < file1
                                                                                    Phone Book
                                                                                      Company
                                                                                   Phone Number

$

This works in bash on my system. All I did was remove the "integer" before the variable definitions.

Note too that getting the width from the stty command allows the function to work dynamically. I can change the width of my putty window and the text will still be centered in window when run.

#!/bin/bash

print_centered(){
  screen_width=$(stty|grep columns|cut -f2 -d';'|cut -f2 -d'=')
  text_length=${#1}
  pad=$((($screen_width - $text_length)/2 ))
  format="%${pad}s%s"
  printf "$format\n" " " "$1"
}

print_centered "center this text please"

exit 0

So I type your code in word for word, and it gives me an error...

syntax error: `screen_width=$' unexpected

Well I've shown it works. Maybe you have a typo or your version of bash doesn't like the "$( )" syntax for command substitution? At any rate you have a couple of examples and the logic so that should get you going.