Hi I'm not used to do things in Bash, so I'm having some problems:
My goal is to look for special files in a folder, and if found generate some other files with the same filenames, but different extension.
Something like:
For Files-that-are-called-"SysBackup*.Now"
do
NewFileName = ChangeFileExt(FoundFilename),BK
GenerateNewfile(NewFileName)
done
The above is of course dummycode, I won't bother you with the code I have done, as it is not working :-)
So the goal should be:
If the folder contains Sysbackup123.now and Sysbackup666.now, I will end up with the files Sysbackup123.bk and Sysbackup666.bk
Thank you for any help
Michael
Fairly straightforward:
for a in Sysbackup*.now;
do
[ -f $a ] && touch $(basename $a .now).bk ;
done
This is how I do it with sh
:
#!/bin/sh
for file in SysBackup*.now; do
if [ ! -e "$file" ]; then
continue
fi
base=${file##*/}
bk=${base%.now}.bk
touch $bk
done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With