I am attempting to do copy a file (or rename a file) by running the script with flags/parameters to give both the source and the destination file name:
#!/bin/bash/
while getopts s:d flag
do
case "${flag}" in
s) copy_source=${OPTARG};;
d) copy_dest=${OPTARG};;
esac
done
echo "Copy a file input with argument to another file input with argument"
cp $copy_source $copy_dest
The output is an error:
sh test_cp.sh -s file1.txt -d file2.txt
Copy a file input with argument to another file input with argument
cp: missing destination file operand after ‘file1.txt’
Try 'cp --help' for more information.
Does cp
(and mv
) not accept parametrized destination?
What am I doing wrong?