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 am attempting to create a script that takes all the files in a directory "in", converts them to pdfs in an "out" directory, and creates a log file of the same name also in the "out" directory.
The script needs to be able to cope with space and control characters in the target file names.
the script I am using at the moment is:
for file in `ls in`
do
echo $file >> "out/$file.log"
date >> "out/$file.log"
# then create pdf files...
done
This creates the log files, but will wrap $file at any spaces.
I have tried using ls -Q, but this creates errors. I have also tried "`ls in`", but this creates a very long file name.
Any suggestions...
Dan
(and restricting file names is not an option...)
the difference is that 'ls in' would provide a list of text strings but the in/* would then be shell substitution so the filenames don't get distorted.
The only problem that I can see with that is that it returns the results as being:
in/Site Report 1.prn
in/Site Report 2.prn
...etc
which makes it a bit more difficult to shift things across to the out directory. For the moment I will need to use a couple of "cd" commands in the script... not really a problem, but if there's a better solution it would be appreciated.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.