Problem: How do you copy a file? Analyze the problem and consider alternate solutions: Objective: reproduce a file. Elements: (output) newfile, (input) oldfile Relations: copy,reproduce, create a copy, photocopy, ... Algorithm: ? 1 2 3 4 5 6 7 8 9 10 11 12 determine which file to copy from find the oldfile if cannot find oldfile, ???? else continue determine which file to copy to find the newfile if newfile exists, ????? else continue prepare (open) oldfile prepare (open) newfile transfer data from oldfile to newfile put away (close) oldfile put away (close) newfile display the outcome Note that our pseudocode is generic enough to follow a manual or a computerized process. To construct a solution in the bash environment, we need to do some preparations: 1. Create a file for each script (do not get into the habit of just adding to the same file - one solution, one file). For each variation (version), copy the current file to a file that identifies the version. For example: ~$ mkdir bin ~$ cd bin ~/bin$ vi copy . . . ~/bin$ cp copy copy.verA ~/bin$ vi copy . . . ~/bin$ cp copy copy.verB ...and so on. 2. In your ~/bin directory (as demonstrated above), create a file called "copy", enter the code as shown below, save the file and change the permissions so that you can execute the file. ~/bin$ vi copy ~/bin$ chmod 705 copy 3. Learn more about bash shell by examining the manual page: man bash Let's return to the problem. From modelling example solutions, a number of questions should come to mind, such as What is a file? regular file? directory? special file? Where do these values come from? are they chosen arbitrarily, by the user, by another program? Identify other relevant information. Identify and describe uncertainties about the interpretation of the problem. Let's examine what happens to our solution as we make different assumptions about the problem Stop and analyze: Explore other alternatives and related assumptions. Explore the implications of ambiguities when analysing a problem. Consider the impact of alternative solutions on various types of users. Plan and document how to test potential solutions. Recognize and control your own biases when choosing a solution. 1 determine which file to copy from 2 find the oldfile 3 if cannot find oldfile, ???? else continue 4 determine which file to copy to 5 find the newfile 6 if newfile exists, ????? else continue 7 prepare (open) oldfile 8 prepare (open) newfile 9 transfer data from oldfile to newfile 10 put away (close) oldfile 11 put away (close) newfile 12 display the outcome Version A: ....the first version is incomplete, yet provides a wealth of information that we address one step at a time. r/bin$ copy.