My idea is to make a script which gives all subdirectories (in my case ˜/MUSIC but on the mac of my wife is it different –> artist/album). In a later fase I would like convert all .wav extensions to mp4 (if not already exist).
But I have already troubles to get the output of the command in to a string array
#!/bin/bash
extFROM=”.wav”;
extTO=”.mp4”;
dir="˜/music";
tree -d
cnt=1;
array;
echo " part 1";
find $dir -type d | while read line
#ls -d -1 | while read line
do
array[ $cnt ] = "$line";
echo "${cnt} "; # : ${array[ $cnt ] ";
let cnt++;
done
echo " part 2";
array=`awk '{print $1}' <find $dir -type d`
for i in array;
do
echo "${i} ";
done
My apologizes for the delay for my late reaction. Part 1 and part 2 are having the same goal.
Thanks @Peter Cordes for the information about to use 'while' instead 'for-loop' reading lines; http://mywiki.wooledge.org/BashFAQ/001 and http://mywiki.wooledge.org/DontReadLinesWithFor And of course for your other reactions, it is great so many usefull input.
@Matthew Bohnsack … nice and easy piece of script, instead of my idea.
@Saul Ortega, this is my output : (of course the tree)
./test.sh: line 15: array: command not found
part 1
find: ˜/music: No such file or directory
part 2
./test.sh: line 28: find: No such file or directory
array
So it has something to do with my script, the directory exist.