Skip to content

Oilshell Usage (The table missing in getting started.md)

andychu edited this page May 24, 2022 · 6 revisions

Oilshell Usage

Task Usage
Running a script as initially written for other shells. (Usually not even minimal quoting/spacing adjustments needed. A bit more may only be required due to implementing the "Common Subset" of consistent and sane shell execution compatibility. For example, if the script was using some inconsistent associative array patterns, or relied on dynamic parsing.) Also already working: Oil language idioms with negligible impact on shell execution compatibility (proc and Oil expressions in const, var, setvar) Execute script in osh interpreter:osh my.sh Or, adapt script, and let it begin with: #!/bin/osh
...to lint shell fragilities.
* Improved scripts will run with less errors in other shells. (The example enables all strict options at once. Individual strict_* options allow fixing issue by issue.)
Add a line near the top of the script, to set a shell option with error fallback: "shopt --set strict:all 2>/dev/null || true" After that execute the script in osh:osh my.sh
...to allow using the Oil language idioms.
* Only a minimized amount of legacy syntax will break. (Mostly only some quoting/spacing adaption needed, except where Simple Word Evaluation now requires adding explicit split/glob functions to previously correctly unquoted variables) Also useful to source libs?
Adapt script to begin with: #!/bin/osh shopt --set oil:upgrade
Coming pretty close to the Oil interpreter. (Intersection of osh & strict & oil.) #!/bin/osh shopt --set oil:upgrade strict:all                                                                     
Using all of the Oil interpeter. (Have everything parsed as Oil syntax, only unavoidable Oil language warts remaining.) Adapt script to begin with: #!/bin/osh shopt --set oil:all Or, simply use: #!/bin/oil
Clone this wiki locally