This Bash script (run) allows you to run a variety of programming languages using a single command. It identifies the programming language based on the file extension and executes the code accordingly. It supports 65 different programming languages, making it a versatile tool for developers working with multiple languages.
- Automatically detects the programming language based on the file extension.
- Supports both compiled and interpreted languages.
- Simple to use with a single command.
- Runs the output binary or script in the same terminal.
The following programming languages and file extensions are supported:
- C++ (
.cpp) - C (
.c) - Python (
.py) - Java (
.java) - JavaScript (
.js) - TypeScript (
.ts) - PHP (
.php) - Go (
.go) - Rust (
.rs) - Swift (
.swift) - Haskell (
.hs) - Kotlin (
.kt) - Ruby (
.rb) - Perl (
.pl) - R (
.r) - Lua (
.lua) - Dart (
.dart) - Scala (
.scala) - Objective-C (
.m) - F# (
.fs) - Elixir (
.exs) - Zsh (
.zsh) - Julia (
.jl) - Lisp (
.lisp,.cl) - OCaml (
.ml) - Clojure (
.clj) - Erlang (
.erl) - Nim (
.nim) - V (
.v) - Crystal (
.cr) - Fortran (
.f90,.f95) - COBOL (
.cob,.cbl) - Pascal (
.pas) - Vala (
.vala) - Prolog (
.pl) - Tcl (
.tcl) - Scheme (
.scm) - Forth (
.fs) - Awk (
.awk) - Makefile (
.mk) - Matlab/Octave (
.m) - Groovy (
.groovy) - Ada (
.adb) - Solidity (
.sol) - Verilog (
.v) - VHDL (
.vhdl) - Racket (
.rkt) - Red (
.red) - XSLT (
.xslt)
Before using the script, ensure the required compilers/interpreters for the languages you want to run are installed. For example:
g++for C++gccfor Cpython3for Pythonnodefor JavaScript- And so on...
You can install them via your system’s package manager like apt, brew, or yum depending on your OS.
- Download the
runscript. - Move it to a directory in your
PATHso you can execute it globally:mv run /usr/local/bin/ chmod +x /usr/local/bin/run
- Ensure that /usr/local/bin/ is part of your system’s PATH.
If an error occurs during compilation or execution, the script will print an error message indicating the problem.
For compiled languages (like C, C++, Rust, etc.), the output binary will be named after the input file (without the extension). For example, hello.cpp will produce an output file named hello, which the script will execute automatically.
- Run a C++ program:
echo "run program.cpp"
This will compile and run program.cpp, and the output file will be named program
- Run a Python script:
echo "run script.py"
If you need to add support for additional languages, modify the case block in the script by adding new file extensions and the corresponding commands to run those programs.