Wildcards not being substituted

Posted by user21463 on Server Fault See other posts from Server Fault or by user21463
Published on 2009-09-29T00:07:22Z Indexed on 2010/04/02 22:43 UTC
Read the original article Hit count: 543

Filed under:
#!/bin/bash
loc=`echo ~/.gvfs/*/DCIM/100_FUJI`
rm -f /mnt/fujifilmA100
ln -s "$loc" /mnt/fujifilmA100

For some reason the variable * doesn't get substituted with the only possible value and gets given the value /home/chris/.gvfs/*/DCIM/100_FUJI. Does anyone have an idea of why?

Please note:

  • If global expansion fails, the pattern is not substituted. I ran the commands:

    chris@comp2008:~$ loc=`echo ~/.gvfs/*/DCIM/100_FUJI `

    chris@comp2008:~$ echo $loc

    /home/chris/.gvfs/gphoto2 mount on usb%3A001,008/DCIM/100_FUJI

    So we can see the expansion should work

  • I have now switched to using:

    loc = `find ~/.gvfs -name 100_FUJI `

    I am just curious why it doesn't work as is.

  • Debugging output using sh -x

echo /home/chris/.gvfs/*/DCIM/100_FUJI

loc=/home/chris/.gvfs/*/DCIM/100_FUJI

rm -f /mnt/fujifilmA100

ln -s /home/chris/.gvfs/*/DCIM/100_FUJI/mnt/fujifilmA100

© Server Fault or respective owner

Related posts about shell