| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | # Copying a directory tree using cpio. |
| 4 | |
| 5 | # Advantages of using 'cpio': |
| 6 | # Speed of copying. It's faster than 'tar' with pipes. |
| 7 | # Well suited for copying special files (named pipes, etc.) |
| 8 | #+ that 'cp' may choke on. |
| 9 | |
| 10 | ARGS=2 |
| 11 | E_BADARGS=65 |
| 12 | |
| 13 | if [scip-shell system . . `[`. $# -ne "$ARGS" ] |
| 14 | then |
| 15 | echoscip-shell system . . echo. "Usage: `basenamescip-shell system . . basename. $0` source destination" |
| 16 | exit $E_BADARGS |
| 17 | fi |
| 18 | |
| 19 | source="$1" |
| 20 | destination="$2" |
| 21 | |
| 22 | ################################################################### |
| 23 | findscip-shell system . . find. "$source" -depth | cpio -admvp "$destination" |
| 24 | # ^^^^^ ^^^^^ |
| 25 | # Read the 'find' and 'cpio' info pages to decipher these options. |
| 26 | # The above works only relative to $PWD (current directory) . . . |
| 27 | #+ full pathnames are specified. |
| 28 | ################################################################### |
| 29 | |
| 30 | |
| 31 | # Exercise: |
| 32 | # -------- |
| 33 | |
| 34 | # Add code to check the exit status ($?) of the 'find | cpio' pipe |
| 35 | #+ and output appropriate error messages if anything went wrong. |
| 36 | |
| 37 | exit $? |