Table Scripting

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Table Scripting
# 8  
Old 04-16-2013
Did you execute it yourself, what are your autocritics?
Then I will give you my point of vue...
# 9  
Old 04-16-2013
wait... I have to indent it? Why? Is there a reason for this???
Maybe i didn't do enough researching.
To add, what are "Autocritics"?
I'm learning slowly, but surely Smilie
# 10  
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?
# 11  
Old 04-17-2013
Code:
trap "rm~/tmp/* 2> /dev/null; exit" 0 1 2 3
employeefile=~/SuitAndTie/HumanResources/employees
looptest=y
while [ $looptest = y ]
do
   clear
   tput cup 1 4; echo "Corporate Employee Addition"
   tput cup 2 4; echo "====================="
   tput cup 4 4; echo "ID number:" 
   tput cup 5 4; echo "Last Name:"
   tput cup 6 4; echo "First Name:"
   tput cup 7 4; echo "====================="
   tput cup 8 4; echo "Add another? (Y)es or (Q)uit:"
   tput cup 4 18; read idnum
   if [ "$idnum" = "q" ]
      then
         clear;exit
   fi
   tput cup 5 18; read lname
   tput cup 6 18; read fname
   if [ "$lname" > "        " ]
      then
      echo "$idnum:$lname:$fname" >> $employeefile
   fi
   tput cup 8 35; read looptest
   if [ "$looptest" = "q" ]
   then
      clear; exit
fi
done

#
#   # Rethink case
#         echo "$idnum:$lname:$fname" >> $employeefile
#       fi
#      fi
#   tput cup 7 34; read looptest
#   if [ "$looptest" != "Y" -a "looptest" != "y" ]
#   #Rethink case
#   then
#      clear; exit
#   fi
#If cancel operation : clear the values and reset looptest in order to
#stay in the loop
#done

I did add a little on the bottom, but they are comments until i can figure out what those commands are even for... I really don't know XD
I'll probably just delete that little section.
I use putty > ubuntu for our server @ school... However, some of the codes you typed out for me, didn't work at all, so i had to rework some, with the help of a few friends and a teacher's help as well. Is that an error on my end? orr what?
The script works fine now, but I do need a markup script, which I can basically copy+paste this one in the [ code ], and just modify a few things... But, the variables that i need to add in order to mark product prices automatically for me with a 40% markup for profit. I'd need Product Name, ID Num, and COGS (cost of goods sold) + markup price...
So it'd look something like...
Product Name: Apron
ID number: 00010010
COGS: 10
Markup: 14
# 12  
Old 04-18-2013
Ubuntu has no ksh (my first line... just be replaced by your shell: Most probable=/bin/bash or /bin/sh ) then it will work... compare what it does and how...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question