This is a reference repo serving as a sharing and quality control for my polygot scripts: The same script can be operated in both UNIX and WINDOWS OSes. This script is generally used various multi-system distributions and fleet control initialization where maintaining multi-OSes end products can be easily done.
Mainly for multi-os decentralized packaging usage:
- 1 common starting point - less communication errors; more control over the package installation.
- Maintainable and documentable - 1 single start point; 1 set of documentation only; 1 easy way to maintain the starting point command.
- Simple and modular - can easily drill down the errors due to modularization and use the most basic commands available in both OSes.
The products are located in the root repository in various versions:
-
posix-batch-powershell.sh.ps1.cmd - capable of running in:
- POSIX Shell mode; AND
- BATCH mode; AND
- POWERSHELL mode.
-
posix-batch.sh.cmd - capable of running in:
- POSIX Shell mode; AND
- BATCH mode; AND
Note
PowerShell knows how to execute batch script. No auto-correction is required.
- posix-powershell.sh.cmd - capable of running in:
- POSIX Shell mode; AND
- POWERSHELL mode.
Important
When executed in Batch mode, it will auto-correct itself to PowerShell and execute it from there.
- posix-powershell.sh.ps1 - capable of running in:
- POSIX Shell mode; AND
- POWERSHELL mode.
While UNIX systems do not demand for file extensions, Windows do have its
complex and heavy requirement for it. As a practice, the file extension shall
always be lead by the UNIX (.sh*
) and ends with Windows (either *.cmd
for
Batch initialization or *.ps1
for PowerShell initialization).
For the highest portability, I recommend keeping the initialization with Batch mode since its execution can auto-correct to PowerShell mode when available (Refer posix-powershell.sh.ps1 for how it's done).
Hence, this is the Polygot script's file extension I would recommend:
filename.sh.ps1.cmd # start by Batch
filename.sh.cmd.ps1 # start by PowerShell
filename.sh.cmd
filename.sh.ps1
It is always advisable to keep this script as simple as calling the OS-specific initializing command rather than develop a fat binary like executable script.
In case you don't know, coding all 3 types of scripts and compile into 1 manually can be a cumbersome task as the output file can easily become 3x larger. Should it be too complex, you should use proper programming languages like Go or Rust.
Please DO NOT abuse it. You have been warned!
This project is licensed under MIT License.