You are not logged in.

#1 2010-07-10 12:03:24

MrGone
Member
Registered: 2009-09-30
Posts: 23

Find gives permission denied on files when executed from bash script.

I've written a really basic script just to check what new music was added to my library over the past n days:

#!/bin/bash

echo "Check for days?"

read days

`find /home/tom/Music/ -iname "*.*" -type f -mtime -$days -print`

If I run the find from the shell it runs fine but the script always gives this error:


./listNewMusic.sh: line 7: /home/MrGone/Music/Smod/SModcast-19.mp3: Permission denied

Anyone know why?

Thanks.

Offline

#2 2010-07-10 12:50:07

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Find gives permission denied on files when executed from bash script.

It is because you're running the find command in a sub-shell.  What is returned by the sub-shell is being run by your script.

Change:

`find /home/tom/Music/ -iname "*.*" -type f -mtime -$days -print`

to

find /home/tom/Music/ -iname "*.*" -type f -mtime -$days -print

Last edited by steve___ (2010-07-10 12:50:38)

Offline

#3 2010-07-10 12:54:34

MrGone
Member
Registered: 2009-09-30
Posts: 23

Re: Find gives permission denied on files when executed from bash script.

Thanks, works a treat!

Offline

Board footer

Powered by FluxBB