Extract directory path from a parameter

i was attempting to extract a directory path that was passed from a parameter with this code

vdir=`dirname $p1`
echo current directory $vdir

it does not work when the parameter passed has wild card on it.
for example

$ sh sample1.sh "/sbin/log/c*.log"
dirname: extra operand `/sbin/log/c1.log'
Try `dirname --help' for more information.
current directory
$

it works when not using a wild card (expanded file)

$ sh sample1.sh "/sbin/log/c1.log"
current directory /sbin/log
$

please help thank you.

The wild card will be expanded in your script. It should work if exactly one single pattern matched; it fails if none or more than one matched.

Try a for loop in your script.

that works thanks.