Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.
#!/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

share|improve this question

4 Answers 4

You mentioned in your response to Tactical Vim that you're running this under sudo -- '~' is going to be expanded differently under sudo vs. under your normal user. Change it to '~chris' or hard code your home directory.

share|improve this answer
    
Using ~ instead of ~chris did that directory to not be matched properly, but the * still manages to not be replaced –  Casebash Apr 2 '10 at 10:03

Are you sure you entered the .sh file exactly as shown here? I just made a test script doing exactly the same thing as you and it works for me.

Maybe something to do with the strange directory name with spaces, %-signs, and commas?

share|improve this answer
    
That is exactly how it was entered. I checked several times –  Casebash Sep 30 '09 at 10:23

Try running your script under 'sh -x' to see some debug output, perhaps it'll provide a clue. I've never seen echo used in this sort of way, it could be something related to that; does it work if you replace 'echo' with 'ls -d' (or similar, not sure your output) instead?

share|improve this answer
    
Tried: ls -d ~/.gvfs/*/DCIM/100_FUJI /home/chris/.gvfs/gphoto2 mount on usb%3A001,003/DCIM/100_FUJI But when I put ls -d in the script it threw Permission Denied even though I sudoed both the script and the ls –  Casebash Sep 30 '09 at 12:12
    
As yesterday mentioned, ~ expands the the home folder of the user running the command (sic, it's more complicated). Try being explicit and naming the direct folder as he mentions. –  troyengel Oct 1 '09 at 19:36
up vote 0 down vote accepted

Okay, I modified my script as follows:

loc=`echo ~chris/.gvfs/*/DCIM/`
sudo rm -f /mnt/camera
sudo ln -s "$loc" /mnt/camera

Notice that the sudo's are inside the script

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.