Should i learn bash scripting




















Because it's just easy. Then I need to do something too complicated like concatenate a string or use arrays, hashmaps etc and I end up rewriting the entire thing in python. I'm sure there are many people that are amazing at writing bash scripts but it's never been very readable. Once you get just a bit complicated languages like PERL are starting to look pretty by comparison.

Also my biggest petpeave bash sed and awk are not compatible between Linux, mac and likely other variants. Also my biggest petpeave bash sed and awk are not compatible between Linux, mac and likely bad variants. I used to quip "in bash, ANY language is your library! The obverse of course is true: any tool can subsume any other in any given environment, and you won;t know til your script crashes. Granted there are tools like this: github.

How many times do we need to re-write the same fix to the same problem. Yeah that's part of the issue. It's easy, it's everywhere just run bash foobar. It's not as easy to write, but I'm really liking go. It's way more complicated and verbose than bash, but at the end of the day i end up with 1 file to copy around. Yeah libraires Build the script and have Once a technology is adopted it's hard to unstick it That being said in your case it sounds like everybody gets the training required to write clean ksh?

So long as they've learnt ksh fully and not "just the easy bits," then my argument remains the same: so long as there is impetus and requirement to learn the language properly, there's no or much less of a problem! Bash is real programming. I wrote tons of modular complex logics and functions with just Bash running on top of many critical backbone servers.

Bash is a beautiful language to me. If I need my program doing floating-point maths. You know Bash loves piggyback anything. It's cute. Yep it's real programming alright. That said, I've seen many cases and been guilty of a few where the logic would have been better moved to other languages, in their own succinct modules, and used bash to tie the pieces together.

It all depends on the use case of course Never tell an engineer they can't do something. Please see: dev. You just The name in the receiving function must be different from the one in the caller function. Recursive functions in Bash are a bit trickier, but I'll post a solution to that later today ;-. I dunno, last I heard and I am not versed in C so I could be talking complete nonesense , C functions return memory addresses I look forward to whatever solution you have to enable getting around the name clash during recursion with reference variables Tai, C functions can only "return" something which can fit in a CPU register, because that is an efficient place to stash information which can be retrieved after the function "returns" - meaning the content of the CPU register gets copied into a stack variable or some other place useful to the programmer.

Semantic shenanigans if you ask me. C functions return typed values. Indeed once the structures grow bigger, programmers tend to revert to output arguments, which are often pointers to structures. Also, for lack of exceptions in C, functions often return error codes, and accept 'output' arguments as well. Exceptions, variants, Severe pain should be your punishment - though there are legitimate cases for it. I'm sure the assembler does emit low level stuff like that. The semantics of the language are copying a value out of the function, though.

In C the semantics what a function can return are limited to something which which will fit in a CPU register because that is what the term return means. The C compiler provides an additional service of promoting or truncating this returned value to match a simple return type.

You can't successfully return any arbitrary local-to-the-called-function stack based struct from a C function, because the content of this struct is undefined as soon as the function returns. You can pass the address of any arbitrary struct into a C function, where it may then get populated. That said, I picked up C 32 years ago, and it remains one of the most popular programming languages.

But I'm truly dazzled you would not be allowed to return a perfectly valid object. Let the compiler inject the correct assembly to accomodate it. What about this one stackoverflow. Wrong, too?

The stackoverflow example returns a value which is the size of an int. That fits just dandy into a CPU register. This article clarifies some things, too: uninformativ. I'll try compiler explorer tomorrow - now's nap time here. There's your compiler trick of silently allocating stack space, and then passing it by reference to the function to get populated.

For large objects this is a significant performance penalty to pay for some syntactic sugar. Can you put a date on that? But thanks. It is indeed very interesting to see how you're drawing totally opposite conclusions depending on your viewpoint.

The crux of this disagreement is the definition of the word "return". In my opinion, creating the semantics of returning an object by silently passing in the reference to a possibly significantly sized return buffer of which the programmer may or may not be aware is not "returning" an object at all. So, is the second example "returning" 3 objects? If not, then why? By implementing the semantic charade of returning a single arbitrary object, modern compilers have accommodated a single case where it appears in source code that a function can return something which will not fit in CPU registers:.

So, where stack heap static data segment does rtn exist? How does the contents of rtn make it back to the caller? More broadly, knowing how to use the shell gives you a second option for interacting with your computer. You can always use the GUI when you prefer, but the command line can provide you with more direct power and control for those times when you need it. Text files are among the most common ways methods to store and handle data.

Almost any data science project is going to involve some work with text files. Being able to handle text files quickly and efficiently is thus a very useful skill for a data scientist. The shell has very powerful text processing tools like AWK and sed , which help with getting acquainted with files and facilitate data cleaning.

This is true both for working locally and remotely. When connecting remotely, GUIs consume much more bandwidth than terminals, wasting resources. Moreover, latency , i. To quote from this article by Nucleus Research:. That trend has accelerated, with only 4 percent of projects running on-premise in There are just a few popular shells bash, zsh, fish, ksh, tcsh, cmd, Windows PowerShell, etc.

For example, the bash commands that you learn in our command line courses will work on Unix-based machines like Macs and Linux computers. Even if their system doesn't use bash, it'll use something similar enough that you'll be able to figure it out.

Research shows that mouse use plateaus rather quickly, while keyboard use, despite its steep learning curve, can be more efficient. Contrary to our expectations, most experienced users rarely used the efficient keyboard shortcuts, favoring the use of icon toolbars instead. A second study was done to verify that keyboard shortcuts are, indeed, the most efficient method. Six participants performed common commands using menu selection, icon toolbars, and keyboard shortcuts.

The keyboard shortcuts were, as expected, the most efficient. Because it is so easy to track all of your activity on the command line, auditing and debugging is much easier. And, as previously mentioned, many of the bash commands you'll learn work in Windows' native sell options like the command prompt anyway.

Also, be very careful not to download and run code as the superuser, or you may find yourself in a pickle. What if you want to try something but you don't have access to Linux or Unix?

This is less than ideal, but you can try a few online resources with very nice front ends to run your scripts, such as:. These online resources can help you become a better Bash programmer. Some other things to keep in mind:. Proud dad and husband, software developer and sysadmin. Recreational runner and geek. More about me. Relive our April event with demos, keynotes, and technical sessions from experts, all available on demand.

Enable Sysadmin. Whether you're new to writing scripts or you've been using Bash for years, there's always something to learn. Boost your scripting skills with these guides, tutorials, and examples. Is there any use for Bash scripting anymore? Asked 11 years, 5 months ago. Active 1 year, 4 months ago. Viewed 49k times. Improve this question. Daniel Harms Daniel Harms 1, 1 1 gold badge 10 10 silver badges 20 20 bronze badges.

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them - Tolkien — mouviciel. What's up with that? Perl's not that hard to pick up!

I have nothing to add to what others have said. BlueRaja, Perl was the "very writable" language ; — Daniel Harms. Show 3 more comments. Active Oldest Votes. Improve this answer. Matthew Flaschen Matthew Flaschen k 47 47 gold badges silver badges bronze badges.

Thank you for that linked question; very useful. If you want the native equivalent of Bash in Windows, you learn the Powershell environment.

Also useful when " most of what you're doing is communicating and piping", though it's between Powershell "cmdlets" instead of venerable standard Unix programs like awk , sed , grep , xpath , etc.

Bash is like the family programming language of linux. Add a comment. Can you give me some more specific examples? Or just one even? I'm not "judging" Bash, I really am trying to learn what people really use it for. Sorry for the tone I had, but what I really mean Is not that you are talking badly about Bash, but just that I don't think It's the time to judge It as "retire-ready".

These are things that Python can certainly do, and more conveniently than bash… — Eric O Lebigot. EOL Although I agree with you and use python or ruby for a lot of tasks, there are still places where you get only bash: I think to the embedded world. Although It is improving everyday, It's hard to find high level interpreted languages inside embedded devices and It's easy to manage them via bash or ash. Show 1 more comment. Morgan 4, 26 26 silver badges 34 34 bronze badges. So, use bash because you don't have to put environment variables in quotes?

My point was that same language is used in scripted mode and interactive mode. It's not the same language. Many commands differ from Linux and Mac. Very good point, Mangostaniko — mikek In Python: for file in os. Your example doesn't use bash at all, it is just an invocation of grep.

It would work in any shell. Quantum7 Quantum7 2, 2 2 gold badges 32 32 silver badges 40 40 bronze badges. Perl shells on the other hand, do exist see Zoidberg search. I've added a os.



0コメント

  • 1000 / 1000