ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a script that changes all file extensions from .jpg to .JPG. I have written the script to go from .JPG to .jpg as well. What I need help with is. How would I edit the script to do either convert them from .jpg to .JPG or .JPG to .jpg
My current script is:
-------------------------------------
#!/bin/bash
# I just run the script and make sure I put a # at the start of the line I don't # need.
for i in *.jpg; do j=`basename "$i" .jpg`; mv -v "$i" "$j.JPG"; done
for i in *.JPG; do j=`basename "$i" .JPG`; mv -v "$i" "$j.jpg"; done
---------------------------------------
How would I make it check for jpg and change it to JPG, if there are no jpg, then it needs to check for JPG and then convert them to jpg.
The following will try to rename JPG in all filenames ending in JPG to jpg. If there are no JPG files, it will try to rename jpg in all filenames ending in jpg to JPG:
Code:
rename JPG jpg *JPG || rename jpg JPG *jpg
It's not perfect, but it's quick - hope it helps...
rename JPG jpg *JPG || rename jpg JPG *jpg
Bareword "JPG" not allowed while "strict subs" in use at (eval 1) line 1.
Bareword "jpg" not allowed while "strict subs" in use at (eval 1) line 1.
Its cool. I just created 2 seperate scripts, one to make it lower case to upper, one to make it upper to lower. Thanks.
Oh and ^^, no shit. I tried if statements, couldn't figure out how to write it. Hence the post.
I'm glad you've got a working solution. Just out of curiousity though - did you try the rename command wrapped in a perl script? I've never seen that error in a regular bash script before (and it works in my bash script).
I just ran the rename command you posted in a command line as root, just to see what would happen. I may play with it later in a bash script. It works fine now with me just having 2 seperate scripts. One makes the .jpg to .JPG the other makes .JPG to .jpg.
oh and what's this supposed to mean??
----------------------------------------
Looks like he changed langs in midflow ;-)
__________________
ahhh I thought he meant I changed languages, as in english to something else... Anyways.. I bet if you run that rename command from the commandline you'll see the bareword error
Umm, no I don't. On my PC it works fine - no errors and it does the rename both ways. It's odd that you're getting that error. The reason I thought you were using perl is that if you look at man perldiag you can see that same error message.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.