best way to automate shell commands - shell script or python scripts or something els
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
best way to automate shell commands - shell script or python scripts or something els
Hi,
I want to automate a few shell commands. I want to compile my program for different options and run it. These options are stored in a file.
So, I am supposed to read all the options from the file.
Compile a particular program with one option at a time.
Run that program.
Then compile again with another option from the file.
Do this till all the options in the file are exhausted.
I am not sure, what is the best way to automate this. Should I write shell scripts or should I try python script or something else.
Like being a good mechanic, being a good system admin requires using the right tool for the job.
This is something that can be done with BASH and in all honesty it's hard to give a good recommendation without knowing how in depth the program being run is, how many options and what they are, etc..
Personally, this sounds like something I would use python for as it's by design an interpretive language that is usually really good at handling input like this easily. But if it's a small set of options and a quick task something a simply as a one-line for loop could get the job done.
If you can give some more detail we can probably give you better answers, I hope some of this info helps.
gcc uses several compile time options like -fdce or -fdse etc. There are 60 such optimization flags documented. I have copy pasted all these documented flags in a file. Now I want to use one flag at a time to compile a program. Then run that program 5 times. After that take another flag from the file and repeat this process until all flags are exhausted.
Now, someone suggested me to use python for this and someone said shell script. I am confused. I dont know both shell scripting and python. I want to learn the one that is best suited for this type of automation.
Now, someone suggested me to use python for this and someone said shell script. I am confused. I dont know both shell scripting and python. I want to learn the one that is best suited for this type of automation.
Build your fundamentals, learn BASH. Then learn another language. Scripting languages are kind of like different types of vehicles, each one gets you from a to b but they all do it slightly different and everybody has their favorite.
If you want to learn python read this, its a great tutorial: learnpythonthehardway.org/
---------- Post added 08-08-12 at 01:13 PM ----------
Quote:
Originally Posted by parangsaraf
Its a simple file like this:
-fdse
-fdce
.
.
.
Now how to put these options in a list to iterate over?
Check my previous post, for loop with a cat statement.
Even if you already know some of the basics this book will fill in alot of the holes and get you into some really cool bash scripting exercises toward the end.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.