Posted on 12-19-2012 01:32 PM
Developed a quick script to do a simple task, remove the iMovie (previous version) folder. While I was thinking of how to do this, I thought... "Why don't I make a script that could handle any folder path", so I did. But now it won't recognize the "(previous version)" folder, thought it appears that it does see the path properly. Here's the script...
#!/bin/bash
## Simple script to remove a folder passed to it.
if [[ $4 ]]; then
if [[ -d $4 ]]; then
echo "Directory found at... " $4
## rm -fdrv $4
else
echo "No Directory found at ... " $4
fi
else
echo "No Variable in Slot 4"
fi
and the path, with spaces and specials escaped... /Applications/iMovie (previous version).localized)
But no matter how I put the folder path in, it comes back with "no's".
No Directory found at ... /Applications/iMovie (previous version).localized
No Directory found at ... /Applications/iMovie (previous version)
No Directory found at ... /Applications/iMovie (previous version)
But if I pass it just the applications, or any other standard folder it works. It works if I pull it out of Casper and change the variables to $1. Is Casper doing something that causes the to break?
Anybody see something I might be missing?
Posted on 12-19-2012 07:26 PM
try putting the path in quotations:
bash$ /Users/test/Desktop/test.sh 1 2 3 "/Applications/iMovie (previous version).localized"
Directory found at... /Applications/iMovie (previous version).localized
echo'd command: rm -fdrv /Applications/iMovie (previous version).localized
if spaces/specials are bashing your script, you can also put the placeholders in quotes:
#!/bin/bash
## Simple script to remove a folder passed to it.
if [[ "$4" ]]; then
if [[ -d "$4" ]]; then
echo "Directory found at..." "$4"
echo "echo'd command: rm -fdrv "$4""
else
echo "No Directory found at ..." "$4"
fi
else
echo "No Variable in Slot 4"
fi
Hope this helps!