- You cannot place
~
inside the quotes. Shell doesn't expand that. - Variable assignment doesn't have
$
before the variable name.
Try this:
DIR=~/Library/Developer/Xcode/DerivedData/
cd $DIR
ls
rm -r -- "$DIR"*
Question
I'm trying to create a sh to remove the contents of Xcode's deriveddate folder. I wrote this, it goes to the desired folder, and list the content, but when I remove the # and try to delete it, than it says
"**line 1: =~/Library/Developer/Xcode/DerivedData/: No such file or directory
Desktop Downloads Movies Pictures clitools.dmg
Documents Library Music Public
override r--r--r-- dajkaferenc/staff for Desktop/Christmas Game update/.git/objects/00/8b8026f772525ccff6c3361ecc6f3eb43d0d82?** "
$DIR="~/Library/Developer/Xcode/DerivedData/"
cd $DIR
ls
#rm -r -- "$DIR"*
Solution
~
inside the quotes. Shell doesn't expand that.$
before the variable name.Try this:
DIR=~/Library/Developer/Xcode/DerivedData/
cd $DIR
ls
rm -r -- "$DIR"*
OTHER TIPS
DIR=~/Library/Developer/Xcode/DerivedData/
cd "$DIR"
ls
rm -r ./*
No $
when you assign a value, only when you read it.
Variables which could contain spaces or other symbols with a special meaning should be quoted.
You are already in the right folder, so you don't need the variable.