I saw this in a post:
Code:
#You can also use variable substitution:
#for file in *.jpg; do
#mv "$file" "${file//b/_}"
#done
And wanted to try to use it because; A. It looks simple, and B. I think its straight Bash as opposed to Perl or something.
I did this with it:
Code:
#!/bin/bash
exec 2>/tmp/script1.log
set -x
grt=`ls /home/teabear/desktop/underfiles`
for file in /home/teabear/desktop/underfiles/$grt ; do
mv "$file" "${file//_files/ }"
done
This moves (renames) only the first folder or file it comes to in the "underfiles" folder. After that the path is lost and mv complains "cannot stat, no such file or directory" for the remaining stuff that is in the "underfiles" folder.
Here is the log file from `exec 2>'
Code:
+++ ls /home/teabear/desktop/underfiles
++ grt='b_files
d_files'
++ for file in '/home/teabear/desktop/underfiles/$grt'
++ mv /home/teabear/desktop/underfiles/b_files '/home/teabear/desktop/underfiles/b '
++ for file in '/home/teabear/desktop/underfiles/$grt'
++ mv d_files 'd '
mv: cannot stat `d_files': No such file or directory
What do I need to understand to go through and rename with mv, all the files in the "underfiles" folder, instead of just the first file it comes to?
Should my question be: "How do I supply the path for $grt to all the iterations in the for loop?"
Thank you for any help.