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.
I recently wrote a Bash script as a backup solution to protect us from ransom-ware threats. It turns out that I'm in love with it, lol. What I would like to know from some of you Bash veterans out there, is what are it's limitations?
I've heard scripting referred to as "sub-programming", but Bash seems to have lots of programming like features such as the use of variables, if's, while's, when's, etc..
So what exactly then, might Bash NOT be able to do?
ANYTHING YOU CAN DO AT THE COMMAND LINE YOU CAN DO WITHIN A BASH SCRIPT!
Read the links in my signature regarding bash scripting, I also wrote a blog and I believe I referred to user Habitual's list of links from within that blog.
Bash is VERY useful.
Bash programming is programming, however there are many other languages.
I feel that the information telling you that it's not quite top notch programming is rather limited in mindset, but everyone is entitled to their opinions.
bash is not really fast, so if performance is an issue you need to use another language. Also I wouldn't implement (for example) a web server or database server in bash, although some simple implementations may exist.
yes, you can make gui with bash... not that I would suggest this as something that you should or even would want to do, but it _is_ possible :-)
Myself, I think bash programming is real programming. Like any language it has strengths and weaknesses. A shell that is even stronger (in my opinion) is ksh; having compound variables and a better form of scoping through pipes. (altough you can fix this in bash)
The major gain is that you can use tools and applications that already implement something for you and you can tie them together adding logic, conditions and checks etc...
But I think that there is also something else to consider ... and that "something else" is . . .
#!shebang !!
Although "Bash scripting" might be "a very nice language" ... ... it was never really intended to be "a full-featured programming language." (The only shell that did attempt to do such a thing was ksh: Dr. Korn's shell.)
When you want to "write a shell-script," you arenot(!) limited to Bash's puny "built-in scripting language." You can, instead, employ any of literally dozens of alternatives: C/C++, Python, Perl, PHP, Ruby, Haskell, JavaScript, Java (ick ...). The end-user will not know and will not care which one you picked.
When you start your script with a "shebang" line, the shell will pass the script-file to that command-interpreter. (For example: #!/usr/bin/php will introduce a PHP script, and so on.) The end-effect as perceived by the user is exactly the same, regardless.
Last edited by sundialsvcs; 06-02-2016 at 09:42 PM.
But I think that there is also something else to consider ... and that "something else" is . . .
#!shebang !!
Although "Bash scripting" might be "a very nice language" ... ... it was never really intended to be "a full-featured programming language." (The only shell that did attempt to do such a thing was ksh: Dr. Korn's shell.)
When you want to "write a shell-script," you arenot(!) limited to Bash's puny "built-in scripting language." You can, instead, employ any of literally dozens of alternatives: C/C++, Python, Perl, PHP, Ruby, Haskell, JavaScript, Java (ick ...). The end-user will not know and will not care which one you picked.
When you start your script with a "shebang" line, the shell will pass the script-file to that command-interpreter. (For example: #!/usr/bin/php will introduce a PHP script, and so on.) The end-effect as perceived by the user is exactly the same, regardless.
So what exactly then, might Bash NOT be able to do?
as has been said already, it is not very fast; complex tasks coded in C might run ten times faster than as a shell script.
bash is insanely feature-rich and as time goes by you will learn to use bash builtin functions instead of external tools like grep and sed.
for simple scripting i try to replace bash with dash whenever possible; dash is much more limited (it is actually possible to read the man page in one go), but also much faster.
recently i found an extremely simple solution to 2 problems, by using python instead of bash, grep, sed & co.
problem 1: get the colors from the current gtk theme.
problem 2: convert RGB color definitions to HSL and back.
instead of writing a complete python script (which i am totally unable to do) i integrated them into my bash script here and here.
If you do anything serious with bash, I find shellcheck to be useful to avoid common mistakes. It can be integrated with some editors as well to see errors while working on a script.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.