Stories
Slash Boxes
Comments

SoylentNews is people

SoylentNews is powered by your submissions, so send in your scoop. Only 16 submissions in the queue.
posted by LaminatorX on Sunday October 12 2014, @09:19AM   Printer-friendly
from the Bad-Ass-Script-Host dept.

When I first learned about Linux in the 90’s, I read that it was possible to even write your own commands to use at the command line. Later I learned about bash scripting, and it wasn’t long before I needed to learn how to loop in bash. Looping in bash is one of the fundamental building blocks of bash programming. It isn’t hard to do at all and is worth learning. The main reason to learn looping in bash is to handle doing the same thing over and over again. They’re easy to do even at the command line. Please follow along as we look a couple of basic examples, and how you can expand on them.

http://www.tidbitsfortechs.com/2014/10/looping-in-bash/

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 2) by VLM on Sunday October 12 2014, @11:12AM

    by VLM (445) on Sunday October 12 2014, @11:12AM (#105024)

    There's a minor problem in the article... by trying to start too simply, other better simpler solutions are available.

    xargs is for more than screwing around with directories with 100K (quantity not length) files.

    Several of the early examples boil down to something equivalent to

    ls | xargs wc -l

    Another interesting strategy not considered is some simple report-ish tasks are very amenable to awk and awk is fast, faster than Perl (and if you've got a truly awful task, whip out a Perl one liner)

    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2  
  • (Score: 2) by FatPhil on Sunday October 12 2014, @11:43AM

    by FatPhil (863) <pc-soylentNO@SPAMasdf.fi> on Sunday October 12 2014, @11:43AM (#105030) Homepage
    I don't awk, but I do notice that lots of awk one-liners I see ought to be sed-able, and I do sed.
    --
    Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
    • (Score: 0) by Anonymous Coward on Sunday October 12 2014, @12:08PM

      by Anonymous Coward on Sunday October 12 2014, @12:08PM (#105033)

      I think that it would be more correct to state that all sed programs can be implemented in awk. Not the other way around, however for most one-liners I probably agree. AWK is actually a full featured programming language that can do advanced math, has arrays, flow control, file I/O, the works. You can implement most things like bc, sed, grep, in awk.

      • (Score: 2) by VLM on Sunday October 12 2014, @12:27PM

        by VLM (445) on Sunday October 12 2014, @12:27PM (#105037)

        "advanced math"

        Well that might be a little optimistic, but awk is pretty awesome at the fairly typical tasks of "gimme the MAX, MIN, AVG, STD DEV" of some set of ... something.

        Reminds me of the project I did some years back importing a medium size engineering dataset into R, then daydreaming of the infinite number of cool things in R, and then nobody wanted anything other than avg, I couldda just left it all in awk...