Suppose you want to make a bash
script which supports no options but acts like cp
, because the cp
supplied by your system does not accept multiple sources.
The usage for the system's (hypothetical and broken) cp
is:
cp source target # target may be a directory
The usage for the script will be:
cp.sh source... target # target must be a directory
Here's a starting point for the script:
#!/bin/bash
tgt="$1"
shift
for src in "$@"; do
echo cp $src $tgt
done
When run with the arguments "a b c d
" (note that d
is the target), it outputs:
cp b a
cp c a
cp d a
The goal is to fix the script to output this instead, while keeping the code simple:
cp a d
cp b d
cp c d