When I run the script, the cursor starts on the wrong line?

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions When I run the script, the cursor starts on the wrong line?
# 1  
Old 10-12-2014
When I run the script, the cursor starts on the wrong line?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data: It's a shell script using a looping logic, trap, tput, if, while. Most of the scripts in this book aren't written for Ubuntu (which is what I'm running) but are supposed to be run on Knoppix or UNIX, so I've found quirks and I'm curious if this is one of them.
Everything seems to be working fine except where the cursor starts for the end user. Instead of starting where the Phone Number line is, it starts at Last Name. I cannot for the life of me figure out why. Everything else executes fine.

Code:
while [ $looptest = y ]
do
  clear
  tput cup 1 4; echo "Corporate Phone List Additions"
  tput cup 2 4; echo "=============================="
  tput cup 4 4; echo "Phone Number:  "
  tput cup 5 4; echo "Last Name   : "
  tput cup 6 4; echo "First Name  : "
  tput cup 7 4; echo "Middle Init : "
  tput cup 8 4; echo "Dept #      : "
  tput cup 9 4; echo "Job Title   : "
  tput cup 10 4; echo "Date Hired  : "
  tput cup 12 4; echo "Add Another? (y)es or (q)uit: "
  if [ "$phonenum" = "q" ]
         then
           clear; exit
  fi

2. Relevant commands, code, scripts, algorithms:
tput, if there's really not much to this...


3. The attempts at a solution (include all code and scripts): I thought this might be a quirk because the book isn't written for Ubuntu, but rather for Knoppix, UNIX or Fedora. I've found several instances where I've had to change a few syntaxes to get things to work right.
I've changed from dash to bash (thank you Google) and that did get one of my other scripts working correctly.



4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course): Northern Virginia Community College, (I'm taking the class online so I've never actually been to the campus, but I think it's in Alexandria, VA), Leon Nicely, ITN-171
(This doesn't actually have to be turned in and isn't required, but I'm doing it to understand my actual homework...which is a bit sad)


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
# 2  
Old 10-19-2014
This probably goes beyond the scope of your course:

Directly addressing screen positions like you do here depends on features a certain terminal type you use may (or may not) offer.

The UNIX terminal concept comes from times where "terminal" was a roll of endless paper running through a printer. It is easy to produce output in a stream-like fashion (just adding at the end), but the printer will have a hard time rewinding the paper and then print over parts it has already printed on. In fact this is what you are trying to do with all the "tput"-statements.

Before you even start debugging your code you might want to find out what terminal type you use:

Code:
echo $TERM

Terminals are handled in a specific way: every terminal type has certain capabilities and ways to use these capabilities. Usually these are some control code sequences which move the cursor, switch printing colours, etc.. All these capabilities are described in a database called "TERMCAP" (terminal capabilties) where the name of the terminal type is the primary key.

When you use a command like tput to position the cursor it first inspects the content of your TERM variable, getting, say, "footerm". Now it queries the termcap database for what the command sequence for moving the cursor in a "footerm" is, getting some control sequence as answer. tput now issues these control sequences and believes the positioning command to have taken place.

This is why you usually get a lot of garbage when you set TERM to a wrong value: tput will get control sequences which may mean nothing to your terminal type and are therefore displayed "as is".

After this little excursion back to your problem: if you want to program input/output masks like you seem to do then shell code is not the tool made with this in mind. This means: it is not impossible, but cumbersome and will not work as reliable as the things for which the shell is made. You might consider "curses" and/or similar libraries to do such things.

I hope this helps.

bakunin
# 3  
Old 10-19-2014
If we assume that TERM is set correctly and that you have a terminal capable of the cursor positioning the tput commands are supposed to do, the code you have shown us is incomplete.

You said you're using "looping logic, trap, tput, if, while", but your loop is not terminated, there is no trap command, you use $looptest and $phonenum but neither of these variables are set, and there is no code that attempts to position the cursor after the Corporate Phone List Additions entry form is written to the screen.

If you don't show us the commands that aren't working correctly, there isn't much we can do to help you fix it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Holding cursor position on one line

Hi there. It's easier to explain this with a pseudo code, I hope this makes sense: var1=hello echo $var1 some kind of loop echo loop counter done How do I hold the cursor position immediately behind the last output so I'd get something like: hello123456789 DOS used to use ","... (5 Replies)
Discussion started by: MuntyScrunt
5 Replies

2. Shell Programming and Scripting

Need to write a shell script that starts one, then kills it, then starts another?

This is on a CentOS box, I have two scripts that need to run in order. I want to write a shell script that calls the first script, lets it run and then terminates it after a certain number of hours (that I specify of course), and then calls the second script (they can't run simultaneously) which... (3 Replies)
Discussion started by: btramer
3 Replies

3. Shell Programming and Scripting

Moving line up if line starts with + sign.

Hello everyone, I'm struggling with this command: awk '!/^\+/{ORS=FS}/^\+/{ORS=RS}1' file1 > file2 What I want to do is to move any line that starts with the + sign 1 up, so its the continuation of the previous. The above command is messing the whole output, can you please let me know... (8 Replies)
Discussion started by: demmel
8 Replies

4. Shell Programming and Scripting

While loop - how to run processes one after another (2nd starts after first completes, and so on)

I'm a programming noob. I'm trying to run a memory intensive process for many files. But when I use the following script, it runs fine for the first 5-7 files, then runs out of memory. Monitoring the output files, it's clear the processes are going on in parallel. Once 5-7 of the files are being... (18 Replies)
Discussion started by: pathunkathunk
18 Replies

5. Shell Programming and Scripting

Merge multiple lines to one line when line starts with and ends with

example: comment Now_TB.table column errac is for error messages 1 - first 2 - second 3 -third ; in this example I need to be able to grab the comment as first word and ; as the last word and it might span a few lines. I need it to be put all in one line without line breaks so I can... (4 Replies)
Discussion started by: wambli
4 Replies

6. Solaris

run a service via startup script (correct me if I am wrong)

Environment Solaris 9 I have configured the Solaris9 as NTP client in which Solaris9 is syncing the time with a windows2008 R2 Server which is runing fine. Now I want that the xntpd service should start at startup. I did this via a script. Kindly correct if I did any thing wrong: 1.)Made... (9 Replies)
Discussion started by: z_haseeb
9 Replies

7. UNIX for Dummies Questions & Answers

Two questions. First one; What are the ways in which a program starts to run.

This is my first post here so hello everyone! I know that a command of the programs name can start a program and clicking on a icon in GUI can as well as a startup shell script but how do I educate myself of the method that starts an application? Does the GUI run a script? What are the ways/ way... (2 Replies)
Discussion started by: theKbStockpiler
2 Replies

8. UNIX for Dummies Questions & Answers

how can I run something as root (modprobe, to be exact) every time computer starts.

I have the root password for my box, but I'm ignorant. So, every time I start my computer, I have to run this command /sbin/modprobe fuse as su, so that I can do other stuff (like mount remote directories locally using sshfs) I guess there's some file, like .bashrc, only it's applicable... (4 Replies)
Discussion started by: tphyahoo
4 Replies

9. Shell Programming and Scripting

How to read a line when it starts with spaces

Hi , I use read command to get the input text, When i try to get the line starting with spaces or ending with spaces it automatically truncates the spaces and displays the remaining content. Code i tried (UserInput.sh): #!/bin/bash echo -n "Enter some text > " read text echo "You... (3 Replies)
Discussion started by: PrakashChinna
3 Replies

10. Shell Programming and Scripting

Whats wrong with this 5 line script!

Hi #!/bin/sh user=$1 if " -eq 0 ] echo "No" else echo "Yes" fi I'm not quite sure whats wrong with this but I know its something silly. Any ideas? Thanks (9 Replies)
Discussion started by: c19h28O2
9 Replies
Login or Register to Ask a Question