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.
Hello.
I am working on following task :
,,Write a script modify with the following syntax:
modify [-r] [-l|-u] <dir/file names...>
modify [-r] <sed pattern> <dir/file names...>
modify [-h]
which will modify file names. The script is dedicated to lowerizing (-l)
file names, uppercasing (-u) file names or internally calling sed
command with the given sed pattern which will operate on file names.
Changes may be done either with recursion (-r) or without it. "
And I have question about recursion. I don't know how to understand it in this case. Option without recursion should just change file names in given directory. Option with recursion should change every folder name and file in given directory or in case that given file name is folder should it enter it and change all files with given pattern ?
Thanks in advance
However: it also sounds like "an abusement of 'bash.'" Given that you can write "a shell script" in any language, I never recommend using Bash to do "serious" programming, especially not stuff that involves recursion. At the end of the day, Bash is only a command-executor, with just enough scripting capability to allow rudimentary looping and decision-making ... to govern exactly what commands are executed and with what parameters. In my experience, you can wind up spending far more time jimmying Bash to do a task that it really wasn't designed to do, than to avail yourself of the Bash feature that was designed for this purpose: #!shebang.
Simply tell Bash to hand over the keys to "the real programming language of your choice," and let Bash sit back and watch it go. The user will be none the wiser.
Last edited by sundialsvcs; 04-11-2016 at 08:52 AM.
Hello.
I am working on following task :
,,Write a script modify with the following syntax:
modify [-r] [-l|-u] <dir/file names...>
modify [-r] <sed pattern> <dir/file names...>
modify [-h]
which will modify file names. The script is dedicated to lowerizing (-l)
file names, uppercasing (-u) file names or internally calling sed
command with the given sed pattern which will operate on file names.
Changes may be done either with recursion (-r) or without it. "
And I have question about recursion. I don't know how to understand it in this case. Option without recursion should just change file names in given directory. Option with recursion should change every folder name and file in given directory or in case that given file name is folder should it enter it and change all files with given pattern ?
Well, since you're working on the task, why don't you show us what YOU have done/written/tried so far on your own???
Read the "Question Guidelines" and the LQ rules. We will be happy to help you if you're stuck, but we WILL NOT write your scripts or do your homework for you. Also, we can't answer your question about the use of recursion, because we don't know what the question parameters are. The script could be written either way.
> Option with recursion should change every folder name and file in given directory or in case that given file name is folder should it enter it and change all files with given pattern ?
The first one. Try ls -lR /tmp for an example.
Edit: let's note that your program usually doesn't get any 'pattern', it is resolved by shell -- unless there is no matching file. Try this:
Code:
/bin/echo *nosuchfile* # pattern is passed to 'echo'
/bin/echo /bin/e* # filenames are passed to 'echo'
I agree that usually the best way to handle this would be to use a higher level language, however, if learning bash scripting this would be a good way to become familiar with
virtually all of its abilities
As TB0ne has said, we will not write the script for you, but if you show us what you have done and where you are stuck, we would be more than lad to assist
I must say that I am not fond of the sed option as there appears to be no way to indicate to use this option (perhaps like having a -s). Some will say that the pattern might be obvious, but the pattern
might also be something as simple as a string with no meta-characters. This would then be difficult to distinguish between a file / directory name and a pattern
I did not want you to write it for me . Just little help with understanding what does recursion mean in this task case Anyway I solved problem with recursion and than another appeared so if you can help me a bit (now I gave some code) please reply in this link: http://www.linuxquestions.org/questi...nt-4175577362/ This thread can be closed. Thank you for replies
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.