Sponsored Content
Full Discussion: Table Scripting
Homework and Emergencies Homework & Coursework Questions Table Scripting Post 302794983 by vbe on Wednesday 17th of April 2013 05:08:10 AM
Old 04-17-2013
Indent is great help when writing : You see if you follow your logic and have not forgotten something... Your peers are more a mood to read your code if clear...
Autocritics: You run your program, then what have you to say?
I dont know to what point of perfection you are to reach: If its just to see you know how to display, read input, and save values to a file, you achieved the task (basically).
If it should be clean code with minimum drawbacks, then there is more work to it:
You should never enter in an appl. that writes/updates if not necessary/wanted, so a test should be done before entering the main loop.
You cannot come back when entering values, its your choice... (why not...) but if the person entering made an error ?
You should in your second test, test integrity of Input (num for first field, if you are happy with your test on lname why isnt fname tested also?...) and offer a "Cancel" input choice so the user can start again..
Your last test is not very usefull as it is for you use the value for loop testing, what happens if user enters what is required like "Y"?

So here is your code (not optimized , so perfectible... for I have no time at the moment and its your work to do, but added some corrections or ideas for you to develop and work on...)
Code:
#!/usr/bin/ksh
#@(#) Add employee to employees file
#======================================================================#
# Script Name: Add Employee                             By: Catori
# version :  001A
#
# Date    :vers. - New or modifications :
#
#========================     BEGIN        ============================#

trap "rm~/tmp/* 2> /dev/null; exit" 0 1 2 3
clear
#employeefile=./humanresources/employees
employeefile=./employees
tput cup 0 4; echo "Add emp? (Y)es or (Q)uit:"
tput cup 0 35; read CONT
if [ "$CONT" != "Y" -a  "$CONT" != "y"  ]
then 
   clear; exit
fi

looptest=y
while [ "$looptest" = "y" -o "$looptest" = "Y" ]
do
   clear
   tput cup 1 4; echo "Corporate Employee Addition"
   tput cup 2 4; echo "====================="
   tput cup 3 4; echo "Id Number:"
   tput cup 4 4; echo "Last Name:"
   tput cup 5 4; echo "First Name:"
   tput cup 6 4; echo "====================="
   tput cup 7 4; echo "Add another? (Y)es or (Q)uit:"
   tput cup 3 15; read idnum
   let IDNUM="$idnum"
   if [ $IDNUM -eq 0 ]
   then 
      clear
      echo "Error: Numeric value expected or value less than 1"
      exit 2
   fi
   tput cup 4 16; read lname
   tput cup 5 16; read fname
   #check blank
   if [ "$lname" > "       " ]
   then
      if [ "$fname" > "       " ]
      then
          DATAOK=OK
   #  Here you should  rethink about the test for a Cancel case
          echo "$idnum:$lname:$fname" >> $employeefile
      fi
   fi
   tput cup 7 34; read looptest
   if [ "$looptest" != "Y" -a  "$looptest" != "y" ]
   #  Here you should  rethink about the test for a Cancel case
   then
      clear; exit
   fi
# If cancel operation : clear the values and reset looptest in order to stay
# in the loop
done

# 
#===========================   End   =====================================#

You should add comments also...
what about a help?( I know in primary task it was not required...)

What shell are you using?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[bash scripting] Generating a table with aligned fields

Hi everyone, I want to write a function which calculates the space needed between fields, to generate a table with aligned fields, like when you type "ls -l", the operating system generates a table with beautifully aligned fields. I've got this code so far: for line in $(cat tmpSearch)... (2 Replies)
Discussion started by: Aveltium
2 Replies

2. Shell Programming and Scripting

Create a table using shell scripting

Hi Can we create a rectangular table as i have attached in the query . This is primarily for populating the created table with data gathered . Hope I made myself clear ... Pls suggest Thanks (1 Reply)
Discussion started by: ultimatix
1 Replies

3. Shell Programming and Scripting

How to get the file size and count of a table using shell scripting?

Hi there, im a beginner to the shell scripting.i trying to extract a table from a db(IMD) and i have to get the count of that table and size of the file. can you help me out how to write the shall scriping for the above query. (2 Replies)
Discussion started by: pawanmamidi
2 Replies

4. Shell Programming and Scripting

Table Scripting

Okay. I've been charged with an assignment to create tables. I "Made" a manufacturing company called "Suit and Tie". I need subdirectories for the company, using three departments: Human resources, Manufacturing, and Sales. 1) mkdir Suit_and_Tie 2) cd Suit_and_Tie 3) mkdir Human... (3 Replies)
Discussion started by: Catori
3 Replies

5. Shell Programming and Scripting

How to update a Oracle table through shell scripting?

My Code is get_week_date() { `sqlplus -s ${DQM_SQL_LOGON}@${DQM_SID} << EOF SET ECHO OFF SET FEEDBACK OFF SET PAGES 0 SET SERVEROUTPUT ON SET VERIFY OFF SET TRIMSPOOL ON (update file_level_qc fq set FQ.DATA_FILE_NAME='Hyvee_Pharmacy_Solutions_201304_v1.txt'... (2 Replies)
Discussion started by: karthick.cho
2 Replies

6. Shell Programming and Scripting

Shell scripting unable to send the sql query data in table in body of email

I have written a shell script that calls below sql file. It is not sending the query data in table in the body of email. spool table_update.html; SELECT * FROM PROCESS_LOG_STATS where process = 'ActivateSubscription'; spool off; exit; Please use code tags next time for your code and data.... (9 Replies)
Discussion started by: Sharanakumar
9 Replies

7. Shell Programming and Scripting

Please help in populating output in table using shell scripting

Below is my code where i tried using table tag to print out put in table but its not working #!/bin/ksh #] && . ./.profile 2>/dev/null if test -f '.profile'; then . ./.profile; fi; #. .profile LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1";... (5 Replies)
Discussion started by: ankit.mca.aaidu
5 Replies

8. UNIX for Advanced & Expert Users

How can i populate the record in to table using shell scripting?

LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1"; pzTitle="$2"; pzMsg="$3"; pzFrom="$4"; pzTo="$5"; pzFiles="$6"; pzReplyTo="$7" ( echo "From: $pzFrom\nTo: $pzTo\nSubject: $pzTitle${pzReplyTo:+\nReply-To: $pzReplyTo}" ] && echo... (1 Reply)
Discussion started by: ankit.mca.aaidu
1 Replies

9. Forum Support Area for Unregistered Users & Account Problems

Creation of Oracle table through shell scripting

Hi, I am trying to create a table through shell scripting . I used a command sqlplus -s to connect to sqlplus and user as sysdba. but there is a problem in it. can anyone please solve this . #!/bin/bash $(`sqlplus -s / as sysdba <<eof create table sample (id,int); insert into sample... (1 Reply)
Discussion started by: Unregistered
1 Replies

10. Web Development

Getting Rid of Annoying Bootstrap Table Borders and Wayward Table Lines

Bootstrap is great; but we have had some issues with Bootstrapped <tables> (and legacy <fieldset> elements) showing annoying, wayward lines. I solved that problem today with this simple jQuery in the footer: <script> $(function(){ $('tr, td, fieldset,... (0 Replies)
Discussion started by: Neo
0 Replies
TPUT(1) 						    BSD General Commands Manual 						   TPUT(1)

NAME
tput, clear -- terminal capability interface SYNOPSIS
tput [-T term] attribute [attribute-args] ... DESCRIPTION
tput makes terminal-dependent information available to users or shell applications. The options are as follows: -T The terminal name as specified in the terminfo(5) database, for example, ``vt100'' or ``xterm''. If not specified, tput retrieves the ``TERM'' variable from the environment. tput outputs a string if the attribute is of type string; a number if it is of type integer. Otherwise, tput exits 0 if the terminal has the capability and 1 if it does not, without further action. If the attribute is of type string, and takes arguments (e.g. cursor movement, the terminfo ``cup'' sequence) the arguments are taken from the command line immediately following the attribute. The following special attributes are available: clear Clear the screen (the terminfo(5) ``cl'' sequence). init Initialize the terminal (the terminfo(5) ``is2'' sequence). longname Print the descriptive name of the user's terminal type. reset Reset the terminal (the terminfo(5) ``rs1, rs2, rs3'' and ``rf'' sequence). EXIT STATUS
The exit status of tput is based on the last attribute specified. If the attribute is of type string or of type integer, tput exits 0 if the attribute is defined for this terminal type and 1 if it is not. If the attribute is of type boolean, tput exits 0 if the terminal has this attribute, and 1 if it does not. tput exits 2 if any error occurred. EXAMPLES
tput cl cm 5 10 clear the screen and goto line 5 column 10 tput cm 6 11 DC 6 goto line 6 column 11 and delete 6 characters SEE ALSO
termcap(3), termcap(5) HISTORY
The tput command appears in 4.4BSD. BUGS
tput can't really distinguish between different types of attributes. Not all terminfo entries contain the reset sequence, so using the init sequence may be more useful. BSD
September 29, 2009 BSD
All times are GMT -4. The time now is 11:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy