Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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 been digging around the net for a solution to my problem and I think I have the answer. I thought I would put it up here to see whether anyone has any better solutions. I have a number of files of the format
Quote:
Hancocks Half Hour - Bill and Father Christmas.mp3
I would like to add an apostrophe for correctness
Quote:
Hancock's Half Hour - Bill and Father Christmas.mp3
I would like to create a shell script rather than moving all 73 myself.
I have got it down to
Code:
#! /bin/sh
for f1 in *.mp3
do echo "converting $f1"
f2=$(awk '{gsub(/cock/, "cock\047")} 1' <<< "$f1")
mv "${f1}" "${f2}"
done
This does the trick but if anyone has suggestions for greater efficiency I would really appreciate any feedback
PC filenames and correct English grammar make poor bedfellows. My recommendation is don't do it. Also, remove whitespace and any other special characters besides ., -, & _ from filenames. HancocksHalfHour-BillnFatherChristmas.mp3 would obviously to most people have the same meaning as the original name. None of the names of files which I created on any of my filesystems contain any other characters but ., -, –, —, _ & alphanumerics.
When using linux file names you will often find scripts that bork when accessing files with names containing spaces or any other special characters. White space and ',(,),! are just some of the characters that linux borks with but seem prevalent in windows systems. You can easily see which files contain unusual characters in the file name if the output of the 'ls' command encloses the file name in double quotes. Those file names always requite special handling for scripts and often other programs.
I second the suggestion above to remove the unnecessary characters rather than add more.
Shell scripts can and should be fixed to correctly handle special characters in file names. The usual method is to put double-quotes around $variables in commands.
On the command line they need extra quoting as well. The tab key helps you with it.
Shell scripts can and should be fixed to correctly handle special characters in file names. The usual method is to put double-quotes around $variables in commands.
On the command line they need extra quoting as well. The tab key helps you with it.
As I stated
Code:
Those file names always requite special handling for scripts and often other programs.
Of course the special characters can be handled. I prefer KISS.
Last edited by computersavvy; 03-21-2022 at 04:37 PM.
Shell scripts can and should be fixed to correctly handle special characters in file names.
Agreed except s/special/all/ - people need to stop using the term "special" for anything that isn't alphanumeric. Computers are tools, and GNU/Linux OSes in particular are about giving/returning power to users.
If it's on a user's keyboard, it's valid in a filename, and apostrophes are one of the more mundane and non-special centuries-old language constructs which users should not have to worry about dancing around just because some programmers apparently feel the need to deliberately write buggy and insecure code.
thought I'd share a perl script I use to change file names to my liking. I don't remember where I got it from, but it contains a comment with a unique
typo: "hypenathe the leading number". Putting that into a search engine led to.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.