LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-01-2016, 06:39 AM   #1
biosboy4
Member
 
Registered: Aug 2015
Distribution: Debian, SUSE, NXOS
Posts: 242

Rep: Reputation: 38
Bash-fu


Hello,

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?

Thanks,
 
Old 06-01-2016, 07:35 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
Old 06-01-2016, 07:47 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,841

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
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.
 
Old 06-01-2016, 09:43 AM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Smile

Quote:
Originally Posted by biosboy4 View Post
So what exactly then, might Bash NOT be able to do?
Thanks,
GUI?
 
Old 06-01-2016, 09:47 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
I find this link invaluable to tell me good do's and don'ts in bash
 
Old 06-01-2016, 11:47 AM   #6
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 703

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by keefaz View Post
GUI?
http://freecode.com/projects/zenity

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...
 
Old 06-02-2016, 09:40 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
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 are not(!) 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.
 
Old 06-03-2016, 09:48 AM   #8
biosboy4
Member
 
Registered: Aug 2015
Distribution: Debian, SUSE, NXOS
Posts: 242

Original Poster
Rep: Reputation: 38
Quote:
Originally Posted by sundialsvcs View Post
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 are not(!) 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.
very nice!
 
Old 06-05-2016, 04:24 AM   #9
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by biosboy4 View Post
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.
 
Old 06-06-2016, 09:12 AM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by biosboy4 View Post
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?

Thanks,
http://www.linuxquestions.org/questi...eniuses-35795/
http://www.subsignal.org/doc/AliensB...0Of%20Contents

What Bash might not be able to do?
"there are dark corners in the Bourne shell, and people use all of them"

and finally,
http://www.tldp.org/LDP/abs/html/index.html

and for later:
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls
 
Old 06-11-2016, 02:27 AM   #11
HerbertJ
LQ Newbie
 
Registered: Oct 2008
Posts: 28

Rep: Reputation: 16
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.

http://www.shellcheck.net/
 
Old 06-11-2016, 11:13 AM   #12
biosboy4
Member
 
Registered: Aug 2015
Distribution: Debian, SUSE, NXOS
Posts: 242

Original Poster
Rep: Reputation: 38
Bash-fu

thanks! you will get some rep for that when I reach my linux box.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Bash Script - Reading User Input while Processing output from Command within Bash cleeky Linux - General 5 05-27-2014 02:57 PM
[SOLVED] Converting Script from Linux (GNU) Bash 4 to Solaris Bash 2.05 - Any cheat sheet? oly_r Solaris / OpenSolaris 6 05-03-2013 08:25 AM
Bash problem : -bash: [: /bin/bash: unary operator expected J.A.X Linux - Software 1 09-22-2011 05:52 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
why did bash 2.05b install delete /bin/bash & "/bin/sh -> bash"? johnpipe Linux - Software 2 06-06-2004 06:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration