I’m trying to do a bash script that will find & copy similar files to a destination directory.
For example, I’m passing a parameter 12300 to a script and I want to copy all files that start with 12300… to a new directory.
like this:
sh script.sh 12300
and here’s the script:
if [ -f /home/user/bashTest/$@*.jpg ]
then
cp /home/user/bashTest/$@*.jpg /home/user/bashTest/final/
fi
This just doesn’t work. I have tried all kinds of solutions but nothing has worked.
The question is: How can I use wildcard with parameter?
When you’re checking for multiple files with
-for-eit can get nasty. I recommend kenfallon’s blog. This is something like what he would recommend:Not sure how the
$@would play in here, or if it’s required.