Thread: Are batch/bash scripts really worth it?

  1. #1
    Registered User Sir Galahad's Avatar
    Join Date
    Nov 2016
    Location
    The Round Table
    Posts
    277

    Are batch/bash scripts really worth it?

    I recently ran into an issue where I was working on a bash script that involved some fairly complex text processing and directory traversal. About half way into the whole affair I realized something. I already have tons of well-tested C++ code at my disposal to do all this stuff...so why on earth am I even bothering with these incredibly limited scripting languages? Just write the damn thing in C++ and pass all the command-processor calls to the system() function.

    The results have been quite satisfying. Not only has it been much easier to automate tasks, but it's also made writing platform-agnostic scripts possible. I'm even toying with the idea of replacing make files using this approach.

    Has anyone else here adopted this technique?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    I think it depends on your use case. The "complex text processing" would likely be a minus for shell scripting if you cannot just invoke some combination of awk and/or sed and such to do the job, but if you can then it could be a plus.

    Quote Originally Posted by Sir Galahad
    it's also made writing platform-agnostic scripts possible. I'm even toying with the idea of replacing make files using this approach.
    You'll run into the same challenges as using say, Python scripts to replace shell scripting and makefiles in the hope of being platform-agnostic: your users will depend on you to compile the code for them, which limits their ability to change the script to say, configuration variables from an ini file (this is similiar to Python scripts that have been compiled so that a Python interpreter is not needed on the system), or if they want full control of the script, they need a C++ compiler (like how without such special preparation a Python interpreter will be needed).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User Sir Galahad's Avatar
    Join Date
    Nov 2016
    Location
    The Round Table
    Posts
    277
    Quote Originally Posted by laserlight View Post
    I think it depends on your use case. The "complex text processing" would likely be a minus for shell scripting if you cannot just invoke some combination of awk and/or sed and such to do the job, but if you can then it could be a plus.
    Good point but of course then you'd be moving further away from platform independance, something I'd rather like to avoid.

    Quote Originally Posted by laserlight View Post
    You'll run into the same challenges as using say, Python scripts to replace shell scripting and makefiles in the hope of being platform-agnostic: your users will depend on you to compile the code for them, which limits their ability to change the script to say, configuration variables from an ini file (this is similiar to Python scripts that have been compiled so that a Python interpreter is not needed on the system), or if they want full control of the script, they need a C++ compiler (like how without such special preparation a Python interpreter will be needed).
    For non-C++ projects that's obviously quite true. Then again if given the option of installing a compiler versus a subsystem like Python or what not, I'd personally choose the former. Maybe I'm just biased though.

    The biggest thing for me is the ability to leverage an existing code base. And C++ has the big advantage of being as close or as far to the metal as you'd like so it's sort of like having a C compiler and scripting language all wrapped into one. And the way things are going now my "scripts" are pretty much 100% platform independant which is a huge plus. I run a dual boot Windows 10 and Linux Mint system with a shared directory for all of my user land files so it's pretty nice to be able to just compile and run these scripts without worrying about platform differences.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    There's a big difference between platform independence in theory, and actual platform independence. You can't just ignore the whole "compiling it" step when evaluating what's easiest.

    I get the attraction to the standardization but the standard doesn't help much when trying to get your code running on a MSP430. It comes with bash, sed, awk, etc. You want to write your processing in C++? You even have all the code written already? Great, all that's left is spending the next month figuring out how to install and configure the development environment and you're all set.

    Target independence is one of the weaker arguments in favor of C++, in any context.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    Sep 2018
    Posts
    1
    Honestly, I'm leaning toward them not being worth it at all, especially in the long run. Maybe I'm wrong, but I'd rather concentrate on some other alternative.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scripts Writing Scripts
    By Fauveboy in forum C Programming
    Replies: 7
    Last Post: 06-03-2014, 08:38 AM
  2. Cygwin bash shell scripts are not executing.
    By indigo0086 in forum Tech Board
    Replies: 3
    Last Post: 08-01-2007, 07:20 AM
  3. Bash Shell Scripts
    By jennydarma in forum C Programming
    Replies: 1
    Last Post: 12-13-2002, 05:24 AM
  4. Is it worth the time....worth the sacrifice?
    By Leeman_s in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-04-2002, 06:33 PM

Tags for this Thread