| 1 | #!/bin/bash |
| 2 | # copydir.sh |
| 3 | |
| 4 | # Copy (verbose) all files in current directory ($PWD) |
| 5 | #+ to directory specified on command-line. |
| 6 | |
| 7 | E_NOARGS=85 |
| 8 | |
| 9 | if [ -z "$1" ] # Exit if no argument given. |
| 10 | then |
| 11 | echo "Usage: `basename $0` directory-to-copy-to" |
| 12 | exit $E_NOARGS |
| 13 | fi |
| 14 | |
| 15 | ls . | xargs -i -t cp ./{} $1 |
| 16 | # ^^ ^^ ^^ |
| 17 | # -t is "verbose" (output command-line to stderr) option. |
| 18 | # -i is "replace strings" option. |
| 19 | # {} is a placeholder for output text. |
| 20 | # This is similar to the use of a curly-bracket pair in "find." |
| 21 | # |
| 22 | # List the files in current directory (ls .), |
| 23 | #+ pass the output of "ls" as arguments to "xargs" (-i -t options), |
| 24 | #+ then copy (cp) these arguments ({}) to new directory ($1). |
| 25 | # |
| 26 | # The net result is the exact equivalent of |
| 27 | #+ cp * $1 |
| 28 | #+ unless any of the filenames has embedded "whitespace" characters. |
| 29 | |
| 30 | exit 0 |