Last active
August 29, 2015 14:09
-
-
Save alexfornuto/35b8ca4275fbf7002c59 to your computer and use it in GitHub Desktop.
addAlphaDir.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Please provide the full path to the directory to organize: " | |
read path | |
touch ~/.addAlphaDir | |
while read -r ~/.addAlphaDir | |
do | |
if [$line_in == $path]; then | |
echo "You've already run this script on that directory. If you do it again, you'll create nested directorys, and have a bad time. \n" | |
exit | |
else | |
echo "Cool, man. \n" | |
fi | |
done | |
pushd "$path" | |
for ch in {a..z} | |
do | |
mkdir new"$ch" | |
mv "$ch"* new"$ch" | |
mv "${ch^^}"* new"$ch" | |
mv new"$ch" "$ch" | |
echo "$path" >> ~/.addAlphaDir.log | |
done | |
Hi Alex,
Yes, sorry for that. Here's an updated version:
#!/bin/bash
echo "Please provide the full path to the directory to organize: "
read path
while read line
do
if [ $line == $path ]; then
echo "You've already run this script on that directory. If you do it again, you'll create nested directorys, and have a bad time. \n"
exit
else
echo "Cool, man. \n"
fi
done <.addAlphaDir.log
pushd "$path"
for ch in {a..z}
do
mkdir new"$ch"
mv "$ch"* new"$ch"
mv "${ch^^}"* new"$ch"
mv new"$ch" "$ch"
echo "$path" >> ~/.addAlphaDir.log
done
So, basically it reads from a file .addAlphaDir.log which you can see in the code "done <.addAlphaDir.log". Why this kind of reading? I found it here: http://stackoverflow.com/questions/4642191/read-line-by-line-in-bash-script. Also, I found out the the "if" statement was wrong, as it needed spaces after the starting bracket and before the ending bracket (which you can see here: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html)
Well Alex, you never did get back to me if this helped you or not?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, GitHub mangled your formatting making it hard to read with proper syntax. In your version, where is 'while read line' pulling 'line' from?