Why is bash an all out programming language?

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
coder123

Why is bash an all out programming language?

Post by coder123 »

Ok let me explain what I mean by this question. I understand how bash is very handy. In fact after being showed how execute (via GUI) a hello world program I made in C (for the purpose of trying to figure that out) which was by writing a tiny script in a .txt and/or .sh file I gained tremendous respect for bash and I even now that think that it's the underlying language behind all execution in Linux. (including some file operations if not all) Having said that I don't understand why it has its own form of variables, loops and conditional statements? Why would it be used in favor of gcc, qt, ect?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29607
Joined: Wed Jul 06, 2011 3:58 am

Re: Why is bash an all out programming language?

Post by xenopeek »

There are dozens of popular programming languages you can use on Linux. Probably hundreds if you count all. They all have their own form of variables, loops and conditional statements. Though I'd say most look very similar (take a look here: https://en.wikipedia.org/wiki/Compariso ... uctions%29).

Bash I use for automating administrative tasks and enhancing my shell experience. I wouldn't use it for programming a GUI application. C/C++ or similar language with a GUI toolkit like Gtk or Qt is much more suited for that.
Image
niowluka

Re: Why is bash an all out programming language?

Post by niowluka »

Not sure if I understand your question. Bash is a OS shell. It has scripting functionality, but effectively it just provides an environment for running binaries ... which can be compiled e.g. by gcc.

There is no 'preference' of bash over gcc, you need a shell (e.g. bash) to run binaries (e.g. compiled by gcc). You tested it yourself: you executed your 'hello world' binary in a bash shell.
coder123

Re: Why is bash an all out programming language?

Post by coder123 »

Thanks for the replies. They helped me narrow down my question more and I ended up asking my friend who's a sys admin. I didn't understand what situations a sys admin would be in where he would need to write up a function of commands.
deadbert

Re: Why is bash an all out programming language?

Post by deadbert »

I have a bash script that I use on new computers to prep them for basic use.

I want to install Sublime Text, PHP5, MySQL, custom icons, and git related tools on all the computers I administrate. I also want to do a software update as soon as I install. Optionally I'd like to restart the computer.

Instead of sitting down and doing this to each PC, I simply write a Bash script that does all that at once. I then have about an hour where I can do other things, instead of babysitting the computer.
Habitual

Re: Why is bash an all out programming language?

Post by Habitual »

deadbert wrote:I have a bash script that I use on new computers to prep them for basic use.

I want to install Sublime Text, PHP5, MySQL, custom icons, and git related tools on all the computers I administrate. I also want to do a software update as soon as I install. Optionally I'd like to restart the computer.
Yes, because we've learned to A.R.T., or 'Avoid Repetitive Tasks'.
We love the free time.
benbadge72

Re: Why is bash an all out programming language?

Post by benbadge72 »

When I first became familar with Unix/Linux and even still now, I see bash scripting as similar to DOS batch files. You can use them as suggested above, avoid repetitive tasks. They may also be used to create prototype programs. By this I mean you can write up something simple in a script, it could only even be a function to grep all texts in a given directory for the string of letters 'tea', for example. Once you figure out the simple implications you could advance a program further.

Maybe you have another script that takes all files with the 'tea' string, trunicates them and sorts them alphabetically. For whatever reason, you decide to combine the two. Well, you already have two simple functions. You can see how it all operates together, see what else is needed to 'bond' the two functions. The scripts give the skeleton to flesh out with a higher level language such as C, C++. You might even port the scripts to Perl, Awk.

The point here being you've got a good skeleton to grow from. That is how I see bash scripting, a langauge as well as a means to prototype. It's also useful to simply A.R.T.
Habitual

Re: Why is bash an all out programming language?

Post by Habitual »

btw: bash is NOT a programming language.
niowluka

Re: Why is bash an all out programming language?

Post by niowluka »

Habitual wrote:btw: bash is NOT a programming language.
Is what I said:
niowluka wrote:Bash is a OS shell.
:evil:
Habitual

Re: Why is bash an all out programming language?

Post by Habitual »

niowluka wrote:
Habitual wrote:btw: bash is NOT a programming language.
Is what I said:
niowluka wrote:Bash is a OS shell.
:evil:
I know and you know. Now he knows. ;)

console and terminal{-emulator} anyone? :twisted:

Don't even get me started on that thing every one calls the "System Tray". ;)
DrHu

Re: Why is bash an all out programming language?

Post by DrHu »

It doesn't have all the feature sets of a language: which is usually more comprehensive in its functions/capabilities
https://en.wikipedia.org/wiki/Shell_script
  • Programming[edit]
    Many modern shells also supply various features usually found only in more sophisticated general-purpose programming languages, such as control-flow constructs, variables, comments, arrays, subroutine and so on. With these sorts of features available, it is possible to write reasonably sophisticated applications as shell scripts. However, they are still limited by the fact that most shell languages have little or no support for data typing systems, classes, threading, complex math, and other common full language features, and are also generally much slower than compiled code or interpreted languages written with speed as a performance goal.
https://en.wikipedia.org/wiki/Bash_(Unix_shell)


Scripting languages: linked from 1st wiki above
Python is considered a good choice
https://en.wikipedia.org/wiki/Scripting_language
https://en.wikipedia.org/wiki/Python_(p ... _language)

One point if you concentrate on understanding BASH, you will find much information about how your system is being organized, as they all (LInux OS) use the shell to initiate many tasks on boot/login
--that includes Ubuntu's upstart system
https://help.ubuntu.com/community/UpstartHowto

Of course you don't have to worry about any of this to use the desktop and any installed applications, which for the most part are all graphical (desktop based)
--only when you use the terminal are you confronted with a visible shell (BASH)
JusTertii

Re: Why is bash an all out programming language?

Post by JusTertii »

Habitual wrote:Don't even get me started on that thing every one calls the "System Tray". ;)
I always thought the System Tray was quite useful...
Locked

Return to “Scripts & Bash”