26

I would like to run BASIC code, like you used to do on older computers, in Linux. (I am looking for a BASIC interpreter that can run OS functions natively)

What options do I have? (Preferably for Debian-based and Arch-based)

2
  • 2
    There are many (not really compatible) versions of basic. Apr 16, 2017 at 14:07
  • 2
    @ThomasDickey I put Debian in the question, as it has/had a Debian tag. Apr 16, 2017 at 15:11

8 Answers 8

26

If you want to run natively in Linux BASIC you have several packages in Debian to choose from:

  • brandy - compatible BBC Micro BASIC - works in a X11 graphical interface, aparently supports sound and graphics;

Brandy is an interpreter for BBC BASIC V, the dialect of BASIC that Acorn Computers supplied with their ranges of desktop computers that use the ARM processor such as the Archimedes and Risc PC, and is still in use on these and compatibles.

   BASIC V is a much extended version of BBC BASIC. 

This was the BASIC used on the 6502-based BBC Micro that Acorn made during the 1980s.

  • bwbasic - byWater BASIC - text mode, claims to be ANSI compatible, has shell aware extensions, and claims to be capable of emulating/have good compatibility with several types of "old" BASIC dialects - including IBM BASICA, Microsoft BASIC and gwBASIC.

bwBASIC can be configured to emulate features, commands, and functions available on different types of BASIC interpreters;

bwBASIC implements one feature not available in previous BASIC interpreters: a shell command can be entered interactively at the bwBASIC prompt, and the interpreter will execute it under a command shell.
For instance, the command "dir *.bas" can be entered in bwBASIC (under DOS, or "ls -l *.bas" under UNIX) and it will be executed as from the operating system command line.

Shell commands can also be given on numbered lines in a bwBASIC program, so that bwBASIC can be used as a shell programming language. bwBASIC's implementation of the RMDIR, CHDIR, MKDIR, NAME, KILL, ENVIRON, and ENVIRON$() commands and functions offer further shell-processing capabilities.

To install them:

sudo apt-get install brandy bwbasic

As for my personal experience, I do prefer bwbasic as it allows to have the power of BASIC in a text command line or shell script.

As an alternative, you also have several emulation packages of computers of the old, that obviously besides the BASIC syntax implement all the environment of some old computer you may want to relive.

Interestingly enough, bwbasic in theory could allow automating operations in Unix e.g. building scripts using the BASIC language. Never tried it though.

9

You wrote in a comment to Foon's answer that

What I mean by "like old computers" is that its just there

Others have provided several different suggestions for BASIC interpreters that you could install on a Linux system, so I won't go there. Modern PCs generally don't come with built-in BASIC interpreters, so you are stuck booting something that can run an installed BASIC interpreter.

Rather, I'll take the above to mean that you want something that starts a BASIC interpreter automatically, similar to but not quite like how early microcomputers (such as the Apple II, Commodore C-64, Zinclair ZX-81, and their ilk) booted into a native BASIC interpreter.

There are basically three ways to do this that I can think of:

Create a desktop launcher that opens a terminal

This is the least invasive, because it works fully within the system and environment you are used to.

Basically, through whatever means your desktop environment provides, you create a program launcher and set it up to launch the BASIC interpreter of your choice in a terminal. For extra effect, you can set specific fonts, colors, etc., to simulate an environment of days gone by. Exactly how you would do this depends on the desktop environment you are using, which you haven't specified, but right-clicking around where you are currently clicking to launch applications and looking for a choice to create a new launcher will be a good start.

Create a separate user account with a BASIC interpreter as the shell

This is a little more involved than a simple desktop launcher, but providers better isolation so you don't risk messing up your own files. First, install a BASIC interpreter; I'll use bwbasic for the example, but anything goes, really, as long as it runs natively in a terminal. Then add a user and set its shell to be the bwbasic interpreter. This can be done through the GUI, but that depends on which desktop environment you are using; the portable approach is to do so in a terminal using useradd. This will be something similar to

$ sudo -i
# grep -q "$(type -pP bwbasic)" /etc/shells || echo "$(type -pP bwbasic)" >>/etc/shells
# useradd --home /home/basic --create-home --shell "$(type -pP bwbasic)" basic

Then, you should be able to enter a clean BASIC environment through sudo:

$ sudo -i -u basic

You can create a launcher (as above) that executes this command in a terminal, if you want to.

Give your normal password when prompted by sudo. You can edit the sudoers configuration to avoid the password prompt if desired, but be aware that editing sudoers is somewhat complicated and even more so, risky; you could lock yourself out of the root account, making it quite difficult to repair the configuration.

Use a BASIC interpreter as init

This is the most invasive approach, but also gets you closest to how early microcomputers worked, by booting directly into a BASIC interpreter. I don't recommend this, and would consider it unlikely to work without significant work, but am including it for completeness.

The Linux kernel accepts a command line parameter (yes, the Linux kernel has command line parameters; you can see the currently booted command line by reading from /proc/cmdline) named init, which specifies which program to execute once kernel initialization is complete. You can configure the boot loader (most likely GRUB) to allow you to boot a kernel entry that says that init should be /usr/bin/bwbasic (or whichever other BASIC interpreter you installed).

For this to work, the BASIC interpreter, as well as all files it requires, must be located on the root (/) file system. This is because one of init's tasks is to mount all file systems, and because you are providing a non-init program as init, the non-root file systems will not have been mounted. (I believe another of init's tasks is to remount the root file system in read-write mode, so by the trivial approach you won't be able to save anything. You might, however, depending on the exact implementation details, be able to have the system execute something like mount -o remount,rw / to remount the root file system read-write.) Your chosen BASIC interpreter must also not depend on anything else that init is responsible for, and you will not have access to any facilities handled by init or by any processes spawned by init (for example, networking or multiuser support).

A kernel command line of something like ro quiet init=/usr/bin/bwbasic will probably get you pretty close to how it looked in the old days.

6
  • Your use of sudo echo does not do what you mean and you're likely to encounter a -bash: /etc/shells: Permission denied anyway as the >> redirect is setup by bash before the rest of the command is evaluated. It's probably best to use type -P bwbasic | sudo tee -a /etc/shells instead. See "permissions - How to insert text into a root-owned file using sudo? - Unix & Linux Stack Exchange
    – shalomb
    Apr 17, 2017 at 17:44
  • @shalomb Good point, thanks for mentioning it. I fixed that, but in a somewhat different way.
    – user
    Apr 18, 2017 at 7:03
  • 1
    @MichaelKjörling A less drastic alternative to using a BASIC interpreter as init would be to configure the init system to use bwbasic instead of agetty and to not start an X11 display manager. (For others who don't know what I'm talking about, the kernel provides various "virtual consoles" accessible via Ctrl+Alt+F1 throuh Ctrl+Alt+F12 and the init system, by default, starts agetty on 1 through 6 and an X11 Display Manager (which provides a login dialog) on 7. Before Upstart and systemd, this was controlled via /etc/inittab.) getty and its descendants handle console login prompts.
    – ssokolow
    Apr 18, 2017 at 17:32
  • @ssokolow Good idea for completeness, but at that point you are only one step ahead of a dedicated user account with a bwbasic shell, so I don't think it really adds much in terms of overall variety.
    – user
    Apr 18, 2017 at 20:03
8

Since everyone seems to be assuming you mean "pre-IBM PC" by "older computers", I'm going to go the other route and offer an answer that interprets "older computers" to mean "IBM-compatibles before Windows 9x".

If, you meant computers running versions of MS-DOS that included QBASIC.EXE, you have three options, depending on how strictly you define running them "on Linux":

  1. If you've still got a copy of QBASIC.EXE kicking around, you could use DOSBox or DOSEMU to run it in a virtualized DOS environment. (Both are available in Debian's repositories and are simple to set up. Just set a folder to be mounted as C:, drop QBASIC.EXE into it, and you're good to go.)

    That'll give you perfect compatibility with old source code, but no integration with the host OS beyond "C: is actually a folder, rather than a disk image".

    I should clarify, however, that there's a trade-off between the two. DOSEMU will run in whatever terminal you want, but won't support the fancy low-level tricks some QBasic stuff used (eg. for specialized graphics modes). The only way to support that is a full emulator like DOSBox... but DOSBox will pop up its own window rather than using your terminal.

  2. FreeBASIC has a qb dialect/mode that aims for perfect compatibility with a large subset of QuickBASIC. (The unsupported stuff is mostly low-level stuff related to the fact that QuickBASIC was a 16-bit real-mode system while FreeBASIC is a 32-bit protected mode system.)

    FreeBASIC offers Linux binaries, but you'll only find it in your package repository if you actually meant "Debian-family distros" rather than "Debian" and are running Ubuntu or an Ubuntu derivative like Mint.

  3. The Linux builds of QB64 aren't even in the Ubuntu repositories, but it specifically aims to be the most compatible protected-mode QuickBASIC descendant and even provides an IDE that attempts to clone the QBasic/QuickBasic IDE.

2
  • As a fourth possible option, it might run with wine, the windows emulator. Aug 13, 2022 at 9:58
  • 1
    Wine will try to invoke DOSBox with a generated config file if it's given a DOS MZ-format executable, which is covered by option 1. They dropped their NTVDM-esque DOS support years ago for being greatly inferior to DOSBox for compatibility.
    – ssokolow
    Aug 13, 2022 at 11:40
8

My Debian systems, and probably most other Linux distributions, have several choices available directly through the package manager. Among them:

  • bwbasic:

The Bywater BASIC Interpreter (bwBASIC) implements a large superset of the ANSI Standard for Minimal BASIC (X3.60-1978) and a significant subset of the ANSI Standard for Full BASIC (X3.113-1987) in C. It also offers shell programming facilities as an extension of BASIC. bwBASIC seeks to be as portable as possible.

  • sdlbasic:

sdlBasic is a small, efficient and multiplatform BASIC interpreter for creating games using the power of SDL library. It was inspired by the old and glorious AMOS.

Homepage (Reference guide)

Wikipedia

4

Just to throw out an alternative: there are multiple emulators for Linux that can run your old computers. As an example, with xkegs, if you boot it up, you should have an applesoft basic prompt waiting for you. Communicating with other linux stuff is an exercise left to the reader (hint: technically, I believe you can redirect output in your emulated apple to the emulated printer, which xkegs will then expose as a network socket which you can use e.g. nc to feed into some other piped applications etc. Not sure if there's a way to go the other way, but expect something similar could be done). I would expect the commodore 64 emulators would similarily have a way to run commodore's basic, etc.

9
  • Yes, there many emulators easily installable in Debian, but kegs does not seem to be one of them (no apt-cache search result). And for some/most of the emulators, you will probably need to get an original ROM from somewhere. Apr 16, 2017 at 17:05
  • You might want to also edit your answer to refer to an emulator, that can be run in a terminal (OP has edited Q sometime in the past) Apr 16, 2017 at 17:12
  • What I mean by "like old computers" is that its just there Apr 17, 2017 at 1:43
  • 1
    @DiamondCoderMan You could set up a user account that uses something like bwbasic, brandy or sdlbasic as the shell, instead of bash. On Linux, that's probably the closest you could practically get to a system that operates like old microcomputers that booted into a BASIC interpreter. You could also pass something like init=/usr/bin/sdlbasic to the Linux kernel, which if it works will get you much closer, but it may or may not even work.
    – user
    Apr 17, 2017 at 12:42
1

There are a lot of alternatives. My suggestion is similar to ssokolow's answer. If you want a "modern" BASIC but with a syntax similar to the old BASIC interpreters, then you should give to BaCon a try. It's a BASIC transpiler which generates native code. The project has a pretty good manual, a lot of libraries and examples, and even an IDE written in BaCon.

enter image description here

2
  • But this isn't for the terminal though May 2, 2017 at 23:07
  • The transpiler works in the terminal. It's small and uses a C compiler to build the executable. The IDE was just an example of how powerful the project is. May 3, 2017 at 0:08
0

The Python-based PC-BASIC offers exactly what you are looking for. Click on Documentation, and note the section entitled "Command-line Interface":

You can run PC-BASIC as a command-line interface by setting the interface=cli (or -b) option. No window will be opened: you can type BASIC commands straight into your Command Prompt/Terminal.

It's available via PyPi, and the website has installers for Linux .deb, Win, and Mac. I can tell you that it's also available in the Linux Mint repository.

-2

You can run a C64 in your browser, and use BASIC that way.

http://codeazur.com.br/stuff/fc64_final/

Be aware the keyboard layout is different, i.e. Shift-2 for quotes.

http://jilltxt.net/wp-content/uploads/C64-keyboard-layout.png

Applesoft BASIC if you prefer- http://calormen.com/jsbasic/

There are emulators of other machines online,
but many of them go straight to whatever program you load,
without emulating the initial keyboard input required to get there.

6
  • 1
    How is this "in a terminal" if you're running it in a javascript-based web browser emulator?
    – Wyatt Ward
    Apr 16, 2017 at 21:07
  • 3
    The "in a terminal" part is in the title of the question Apr 16, 2017 at 22:15
  • 1
    @Doyousketch2 Look at the title a little more carefully. i.imgur.com/jDBZVEO.png
    – Wyatt Ward
    Apr 17, 2017 at 13:37
  • 1
    It was even in the first revision title, which read How to run BASIC code in a BASH terminal?
    – user
    Apr 17, 2017 at 13:43
  • 2
    If it is software meant for a C64 or other 8 bit system, emulating a whole machine is indeed the best idea - very few non-trivial basic programs from that era even pretend to be hardware independent in the slightest! Apr 18, 2017 at 8:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .