What do you think about FB as a bash scripting alternative?

Linux specific questions.
Posts: 51
Joined: Aug 02, 2017 12:54

What do you think about FB as a bash scripting alternative?

Postby Achaean » Jan 06, 2018 2:07

I know that the preferred way to do things in Linux is the bash scripting and as a 2nd option many users prefer Python (or a mixed script with both bash and Python scripts) and than comes Perl.

But at my opinion, FB produces executables, light in resources and very effective (if you spend some tine properly coding it).
FB requirements (specially for such small console programs) are really minimal, so what do you think?
Did you ever try FB as a bash script alternative? With what results?
If not, will you try it?

PS. I was using QB back at my good-old-DOS days (I'm 50yo.) as a BAT scripting alternative, because I wasn't quite fond of DOS scripting capabilities.
Of course Linux is a superior OS and bash (and the rest of consoles) are really packed with advanced features, but I still think that FB is a really strong alternative. You can use color, sound, customized input (eg. input 2 character, without the need for pressing Enter), etc.

PS1. I was looking KTimer (the KDE countdown timer, https://www.kde.org/applications/utilities/ktimer/)
It hasn't an option for a specific time alarm (only for countdown) and in order to achieve it, requires from the user to write a bash script.
I have nothing again scripts, but launching an FB program, I think is a way better solution.
Posts: 1610
Joined: Feb 26, 2007 5:32

Re: What do you think about FB as a bash scripting alternative?

Postby caseih » Jan 06, 2018 2:39

In my opinion, no, FB is not a suitable bash scripting alternative.

Bash (well any shell language) is preferred for good reasons. For one, they are interpreted languages, so they are easy to create, edit, and run, without the need for compilation. This is a desired feature. There's no advantage to a compiled binary here. Scripts are by nature usually I/O bound. And most importantly scripts are somewhat platform-independent. The same script will run on 32-bit machines, 64-bit machines, or a Raspberry Pi. This last bit can't understated. It's extremely important.

Furthermore, the basis of shell script use is the pipe, which bash has integrated syntax for. The line between external processes and internal language functions is blurred, if not completely indistinct. This makes shell scripting with a language like bash extremely powerful. Entire new programming constructs can be made up of chaining other units (processes). FB has none of that in the language. And actually in this regard Python isn't really a good scripting language either. People have tried to do various things to make Python more suitable to replace bash, but there are limits to what they can do without syntactic support for external processes and pipes in the Python language. And even when people try to shoehorn python into a role where bash is more appropriate, the resulting syntax is ugly, to say the least:

Code: Select all

shell.ls.pipe(shell.sed(args=['-e', '"s/blah/blah/g"']))


Code: Select all

ls | sed -e "s/blah/blah/g"

Granted python doesn't need to call many of the external programs that bash does, since things like regexes are built in. And in some respects the same goes for FB.

That said, Python's lack of integral piping isn't always a problem. Python's generators very much fulfil the same role. So I have used python successfully for some fairly complicated scripting that calls external processes (I wrote my own subprocess wrapper to grab standard out, standard error, and feed standard in). FB has nothing like Python generators.

Bash's syntax is arcane to say the least, but it's really good at what it does. FB serves a different purpose in my opinion.
Posts: 236
Joined: May 29, 2014 22:01
Location: ID

Re: What do you think about FB as a bash scripting alternative?

Postby nimdays » Jan 06, 2018 3:08

For scripting, I prefer TCC(Tiny C Compiler)


Code: Select all

#!/usr/local/bin/tcc -run

void main(){printf("hello\n");}
Posts: 530
Joined: May 27, 2005 6:20
Location: Limoges, France

Re: What do you think about FB as a bash scripting alternative?

Postby jdebord » Jan 06, 2018 8:08

The latest version (0.9.27) of TCC is here :


You can generate TCC scripts from FreeBASIC :

Site Admin
Posts: 3410
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada

Re: What do you think about FB as a bash scripting alternative?

Postby coderJeff » Jan 06, 2018 15:31

Here is an example of using fb to code something that I have seen typically done in a bash script:

Forum Post:
`git dirs' custom command to get git status for multiple directories recursively

Code gist:
https://gist.github.com/jayrm/b1fbc8199 ... 076fc090d2

I can't say if it is better or worse than a bash script, just something that I tried.
Posts: 3064
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL

Re: What do you think about FB as a bash scripting alternative?

Postby marcov » Jan 06, 2018 17:49

I do a lot of scripting in Delphi and Free Pascal, a similar situation as with FB. The main motivation is simply recycling the language knowledge you already have.

Free Pascal even has a compiler driver (instantfpc) that you can use in a *nix shell shebang. Just run the source, and it will autocompile to tempdir and then run, or run directly if not modified since last compile.

One could make something like that for FB too I guess. You just need easy stringhandling and a bunch of utility routines like

  • run this command and return the stdout and stderr output in a string
  • built-in archive support (zip, tar, gz, I would like more)
  • mime/uuencode streamfilters.
  • sha/md5 checksums for simple (non security) integrity checks
  • get a file or webpage over http. (https is going to mess with this in the future though, will be harder to do without dlls)
  • modules for xml,html,ini parsing


When I first started it, it was painful, but after a while, the utility functions are mature, and it gets easier.

My biggest example is a script that runs various svn query commands (eligible list, and log per revision), and maintains a cache from which it generates SVN merge status overviews (static html pages, updated in cron job, run time 3s on 1.2GHz system). Such things with binary caches etc are not that easy to do in bash.

I also have various scripts that use a library that can read and save freepcb (PCB circuit design) files, and patch them, duplicate or move components around etc. It is only half automated often requiring multiple passes (read file back in FreePCB, move one component, and then the next scripted stage. This readback cycle updates internal administration in the file after modifications).

These originate when we made a 14x16 led lamp where each led is individually switchable and pwmable per row. (and another per row kill if no led is on). It has 1000+ components, and doing it by hand was simply not possible.

I do use windows batch files and shellscripting, but usually only for pretty straight forward sequences of commands, not much logic. If it gets more involved, I usually go to the programming language I know best. I also combine them a lot. a HLL driver program, and bunches of shell/batch scripts to parameterize them.

p.s. piping is IMHO overrated as a general programming concept. It doesn't scale very well beyond basic usage. And most HLLs have stream classes to do something similar but different. More powerful, but less concise and simple.
Last edited by marcov on Apr 16, 2020 20:40, edited 3 times in total.
Posts: 1610
Joined: Feb 26, 2007 5:32

Re: What do you think about FB as a bash scripting alternative?

Postby caseih » Jan 06, 2018 22:21

Speaking of tcc and the instantfpc shebang utility, I completely forgot that I had written a wrapper (in bash of course) to let you you do similar things with FB. It was called fbrun. viewtopic.php?f=5&t=23885&p=210937#p210937

It's pretty crude, and could use refinements, such as a binary cache, and I doubt it's secure enough in it's use of temporary files to use in a CGI context with a web server.
Posts: 51
Joined: Aug 02, 2017 12:54

Re: What do you think about FB as a bash scripting alternative?

Postby Achaean » Jan 07, 2018 14:41

That was a great deal of knowledge!

I didn't know, about those possibilities.
I'll take a thorough look at them.
THANKS guys for sharing!!! ;-)

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 3 guests