I am working on a simple shell script to change a file one.PDF
to one.pdf
. I have this file stored in a folder called Task1.
My script is in the same directory as Task1. Called Shell1.sh
When I run it Task1 becomes Task1.pdf but the file inside one.PDF doesn't change. I need it the other way around but nothing I try seems to work I keep alternating between a syntax error, mv not being able to move because a resource is busy or just renaming the directory.
Can anyone tell me what I'm doing wrong?
#!/bin/bash
#shebang for bourne shell execution
echo "Hello this is task 1"
#Initial prompt used for testing to see if script ran
#/rename .* .pdf *.pdf // doesnt work
#loop to iterate through each file in current directory and rename
for file in Task1;
do
mv "$file" "${file%.PDF}.pdf"
done
for
and globbing, there seems to be a conceptual misunderstanding.for
really only works on a set of strings, separated by the value of the variable$IFS
. It does not do any logic (like reading the content of a folder) by itself. That's whatTask1/*
does, triggering the shell to do the hard work. – Boldewyn Jan 24 '17 at 09:13.three.PDF
for some reason the script ignores it. I think it's because the dot makes it hidden. But I don't know how to make my loop access it. Any advice? – Callat Jan 24 '17 at 15:02dotglob
option:shopt -s dotglob
– heemayl Jan 24 '17 at 15:21shopt
lets you tweak the built in behavior-s
is an option to affect the built in names. anddot glob
contains all the strings that start with a dot. Geez I probably would have never found that on my own. Thanks a bunch! – Callat Jan 24 '17 at 15:35