What happens if you temporarily put extra echo statements after some of the variable assignments, especially those that contain pattern matching operators? Do you get the desired result? Also where does the function "Createfile" end and where does it get to be called? Why do you need the find command if you just need to rename a single file?
Thanks ahead. I made a post to forum, but never got a anwer.
Maybe you know someone who still can help me.
#!/bin/bash
----------Dont know exactly but my code ---
touch > /tmp/newfilename
umask 077 && mkdir /tmp/tempdir.$$)
exit 2
----------------------------------------
usage () {
echo
echo "Usage: `basename $0` <search dir> <old ext> <new ext>"
echo
}
if [ -z "$3" ]; then
usage
exit 1
fi
OLDEXT=${2/#.}
NEWEXT=${3/#.}
find "${1}" -iname "*.${OLDEXT}" |
while read F
do
NEWFILE="${F/%${OLDEXT}/${NEWEXT}}"
echo "mv \"${F}\" \"${NEWFILE}\""
mv -f "${F}" "${NEWFILE}"
done
exit 0
Basically I would like to type to terminal a line like this:
sh myshellscriptname.sh temporaryfolder temporaryfile filecase1 filecase2
like : sh script.sh test file.txt txt TXT -> it would make a folder called test a file calldes file.txt and then change .txt to .TXT or vice versa and when i press CTRL + C - then the temporary file and folder will be deleted.
Greetings,
my 2 cents:
I have not much time to understand all you are trying here and I dont use bash...
So my remarks would be more like "If you were using /usr/bin/sh, ..."
1) The beginning:
#!/usr/bin/sh
#----------Dont know exactly but my code --- # --- Isnt valid for comments...
touch ./tmp/newfilename # So use <#>
umask 077 && mkdir ./tmp/tempdir.$$ # no ) at the end...
#exit 2 # otherwise your program stops here!
#-----------------------------------------
usage () {
echo
echo "Usage: `basename $0` <search dir> <old ext> <new ext>"
echo
}
if [ -z "$1" ]; then # why $3? what about the other
usage # expected arguments ?
exit 1 # at least now it will show up if you type
fi # nothing more than the programs name...
OLDEXT=$2
NEWEXT=$3
echo OLDEXT=$OLDEXT # when things dont work, display what you loaded
echo NEWEXT=$NEWEXT # in order to check you did initialize some VARs
# and have an idea where you are in your code
# at execution...
your main:
NEWFILE="${F/%${OLDEXT}/${NEWEXT}}"
Since I dont use bash for me it will be difficult to say what is not working...
In sh though I doubt it can be done that way...
Why are you not using basic sh ( for compliance...)?
So now you have the beginning in working order
Explain me your choice for your while loop (If it should work in bash, Im no help...)