Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to find "old" folders in /volume1/photo/ipcam which are named like "????-??-??" and move corresponding folders within dropbox (with the same directory structure /ipcam/...) to the subfolder /ipcam/archive. The find command below (with the appropriate values used instead of the variables) works fine when used on the commandline but doesn't if used in a script:

via commandline:

find /volume1/photo/ipcam -maxdepth 1 -type d -name "????-??-??" -mtime +0 -exec sh -c 'echo /home/pi/Dropbox-Uploader/dropbox_uploader.sh move /ipcam/$(basename {}) /ipcam/archive' \;

via script:

#!/bin/bash    
path2disc="/volume1"
source="$path2disc/photo/ipcam"

dropboxtool="/home/pi/Dropbox-Uploader/dropbox_uploader.sh"
dropbox="/ipcam"
dropboxarchive="/ipcam/archive"

find $source -maxdepth 1 -type d -name "????-??-??" -mtime +0 -exec sh -c '$dropboxtool move $dropbox/$(basename {}) $dropboxarchive' \;

I think something is wrong with the quotes in the "script" version, but not sure.

PS: using the following version on the raspberrypi: Linux raspberrypi 3.10.24+ #614 PREEMPT Thu Dec 19 20:38:42 GMT 2013 armv6l GNU/Linux

share|improve this question
1  
Variables don't get substituted inside single quotes. Try double quotes instead: ...-exec sh -c "$dropboxtool move ..." \;. In your command line version you didn't used variables at all, so this worked. –  mpy Feb 18 at 19:42
    
thanks for your tip! You're right with the double quotes -exec sh -c "$dropboxtool move $dropbox/$(basename {}) $dropboxarchive" \;. But now I have another problem with the statement in the script: The $(basename {}) doesn't work correctly - instead of the name of the folder the whole pathname including the folder name has been substituted /volume1/photo/ipcam/2014-02-20. Do you have another tip to solve also this problem? –  Martin Gross Feb 22 at 12:08

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.