コピーするファイル(*.cpp
)とコピーするディレクトリ(cfiles/backup
)に渡す必要があるbashスクリプトがあります。問題は、ディレクトリ内のすべてのファイルではなく最初のファイルのみをコピーすることです。getoptsでディレクトリにファイルを検索してコピーする
#!/bin/bash
while getopts "ab:" input; do
case $input in
a)
#an option
;;
b)
# Get the wild card and destination passed in
# wildcard=$OPTARG
dest="${@: -1}"
#Make the directory if it doesn't exit
mkdir -p $dest 2>1
find . -name "$OPTARG" -type f -exec cp {} $dest \; 2>1
printf 'string = %b| destination = %b\n' $OPTARG $dest
;;
?)
echo "Error! Invalid option provided" >&2
exit 1
;;
:)
echo "Option -$OPTARG missing parameter!" >&2
;;
esac
done
問題はそれだけで1つのファイルをコピーすることですどのような洞察に感謝します!
2> 1になる可能性があります> –