Table Scripting

  1. The problem statement, all variables and given/known data:

I have to make a manufacturing company. I need subdirectories for the company using three departments: Human Resources, Manufacturing, and Sales. I also need three scripts in order to create tables for each sub directory. Each script should ask for the department name, and for that department, create 5 sales persons with ID number and Name.
Stopping there (as there's more to ask, but i'm pretty sure i can finish the rest...)

  1. Relevant commands, code, scripts, algorithms:

Vi Script[1-3] ? ? ?
mkdir
cd

  1. The attempts at a solution (include all code and scripts):

1) mkdir Suit_and_Tie
2) cd Suit_and_Tie
3) mkdir Human Resources
4) mkdir Manufacturing
5) mkdir Sales
6) ???? I know i need a script, so using Vi Editor to start with will help. I am not familiar with the commands within it, especially in order to create tables that ask for each department name, so any help would be appreciated.

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Columbia Junior College - Sonora, California, USA, Ida Ponder, CMPSC9

What OS are you on?
Did you look at what you created with mkdir? ( use ls -l ...)
Isnt there something wrong?...
Since a script is a text file, yes you will have to use vi... but I am not sure about tables for you seem only to begin so what you call tables I understand as "files" now its up to you to say how the the fields are separated...
A script will not be executable just like that so look at chmod command, and the commands you put in a shell script are not vi internals but true unix commands so read again your notes so far on the commands you already know and submit to us a beginning of script so we can do our comments if you wish...

You will need variables to store what people have typed
(hint: you will need read command, so look what it does in a shellscript...)
You will have to display your screen, what command do you use for that?

Once someone entered values in your variables, you will want to write their content in a file...

Ubuntu.
I'm not sure if anything is wrong, because all i needed was subdirectories within the "suit_and_tie" directory. I did look, and it's right where i needed it, at least i think so.. (you have me really thinking if i did something wrong now XD)
Yes, chmod 755 would work perfectly to make the script file executable, i believe.

By variables, do you mean system variables, like columns? Or how A = 1 and etc? I'm very slow when it comes to programming variables ....

Well What do you expect from your command:

3) mkdir Human Resources

?

P.S.
shell script-ing IS programming...

Where is this script then?

Oh~ I did it the right way, i just typed it here, wrongly...
mkdir "Human Resources" is what i meant to put.
The script isn't made because i don't even know how to start it... I am not familiar with scripting too well, however, I have been researching since i've posted this, but still nothing... Guess i'm just really slow when it comes to scripting.

To start would be to write down the algorithm / pseudocode of what is being asked, once validated, transcript into shell code (commands).
Why 3 scripts?
Since you are asking for which dept.... One can do the job...

Because each script is going to be doing three different things.
Human Resources script will have the sales persons(five of more) with ID numbers and names within it.
Manufacturing script will have all the products manufactured with part numbers, product names, Cost of Manufacturing, and sell price with 40% markup or more.
and the Sales script will have all the products sold: Salesperson ID, part numbers, costs of goods sold, and gross profit.

After that, i need to generate a report, gathering data from each department's data files created by the scripts.
I simply do not know what my teacher means when she writes "Write three scripts to create tables, "flat database files, using colon delimiters. Each script should ask for the department name."
I cannot write pseudocode or an algorithm to something I don't even understand. So when I figure out the algorithm, i'll try starting the script...

i'll read some more on unix/linux shell scripts and programming shells, as well as variables, environment and configuration variables, shell variables, and operators.

---------- Post updated at 07:20 PM ---------- Previous update was at 10:21 AM ----------

Ahh! Here we go!!
How does this script sound?

#=============================================
#Script Name: Add Employee
#By: Catori
#
#=============================================
trap "rm~/tmp/* 2> /dev/null; exit" 0 1 2 3
employeefile=./humanresources/employees
looptest=y
while [ $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
   if [ "$idnum" = "Q" ]
   then 
      clear; exit
   fi
   tput cup 4 15; read lname
   tput cup 5 15; read fname
   #check blank
   if [ "$lname" > "       " ]
   then
      echo "$idnum:$lname:$fname" >> $employeefile
   fi
   tput cup 7 34; read looptest
   if [ "$looptest" = "Q" ]
   then
      clear; exit
   fi
done

Did you execute it yourself, what are your autocritics?
Then I will give you my point of vue...

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 :smiley:

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

#!/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?

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

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