forked from amber-lang/amber-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
199 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,5 @@ | ||
# Examples | ||
# Example Scripts | ||
|
||
Here is an example script to periodically install software updates on an Ubuntu system. The update commands are wrapped in a `main` block, so that all commands between `$` signs can pass up errors with the `?` operator. The script will stop in that case and not execute any further commands. | ||
> WARNING: Experimental standard library is used here. The full documentation covering it will be created soon as it get's more stable. | ||
```ab | ||
import { exit } from "std" | ||
main { | ||
// Print output and log it at the same time. | ||
$ exec > >(tee -a /var/log/autoapt.log) 2>&1 $? | ||
// Log the current date so that we can check when any failed runs happened. | ||
$ date $? | ||
// Internet is slow on Austrian trains. Check the Wifi SSID and stop in that | ||
// case. | ||
silent unsafe $ iwgetid -r | grep -E '(OEBB|WESTlan)' $ | ||
if status == 0 { | ||
echo "Skipping updates because of slow Wifi" | ||
exit(0) | ||
} | ||
$ export DEBIAN_FRONTEND=noninteractive $? | ||
$ apt update $? | ||
// By default answer all user interaction questions with yes, for example | ||
// for debconf. | ||
// Use the old configuration file when new config files arrive. | ||
// Also say yes to setting up config files. | ||
$ yes '' | apt \ | ||
-o Dpkg::Options::=--force-confold \ | ||
-o Dpkg::Options::=--force-confdef \ | ||
-y --allow-downgrades --allow-remove-essential \ | ||
--allow-change-held-packages \ | ||
upgrade $? | ||
// Clean up any packages that are not needed anymore. | ||
$ apt autoremove -y $? | ||
// Also update Snap packages. | ||
$ snap refresh --color=never --unicode=never $? | ||
} | ||
``` | ||
Here, you’ll find a collection of practical scripts designed to help you quickly grasp the fundamentals and advanced features of the Amber programming language. Whether you are new to programming or an experienced developer, these examples will guide you through. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Ubuntu Updater | ||
|
||
Here is an example script to periodically install software updates on an Ubuntu system. The update commands are wrapped in a `main` block, so that all commands between `$` signs can pass up errors with the `?` operator. The script will stop in that case and not execute any further commands. | ||
|
||
```ab | ||
import { exit } from "std" | ||
main { | ||
// Print output and log it at the same time. | ||
$ exec > >(tee -a /var/log/autoapt.log) 2>&1 $? | ||
// Log the current date so that we can check when any failed runs happened. | ||
$ date $? | ||
// Internet is slow on Austrian trains. Check the Wifi SSID and stop in that | ||
// case. | ||
silent unsafe $ iwgetid -r | grep -E '(OEBB|WESTlan)' $ | ||
if status == 0 { | ||
echo "Skipping updates because of slow Wifi" | ||
exit(0) | ||
} | ||
$ export DEBIAN_FRONTEND=noninteractive $? | ||
$ apt update $? | ||
// By default answer all user interaction questions with yes, for example | ||
// for debconf. | ||
// Use the old configuration file when new config files arrive. | ||
// Also say yes to setting up config files. | ||
$ yes '' | apt \ | ||
-o Dpkg::Options::=--force-confold \ | ||
-o Dpkg::Options::=--force-confdef \ | ||
-y --allow-downgrades --allow-remove-essential \ | ||
--allow-change-held-packages \ | ||
upgrade $? | ||
// Clean up any packages that are not needed anymore. | ||
$ apt autoremove -y $? | ||
// Also update Snap packages. | ||
$ snap refresh --color=never --unicode=never $? | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,92 @@ | ||
{ | ||
"docs": [ | ||
{ | ||
"path": "getting_started/getting_started", | ||
"title": "Getting Started", | ||
"docs": [ | ||
"docs": [ | ||
{ | ||
"path": "getting_started/installation", | ||
"title": "Installation" | ||
"path": "getting_started/getting_started", | ||
"title": "Getting Started", | ||
"docs": [ | ||
{ | ||
"path": "getting_started/installation", | ||
"title": "Installation" | ||
}, | ||
{ | ||
"path": "getting_started/usage", | ||
"title": "Usage" | ||
} | ||
] | ||
}, | ||
{ | ||
"path": "getting_started/usage", | ||
"title": "Usage" | ||
} | ||
] | ||
}, | ||
{ | ||
"path": "basic_syntax/basic_syntax", | ||
"title": "Basic Syntax", | ||
"docs": [ | ||
{ | ||
"path": "basic_syntax/data_types", | ||
"title": "Data Types" | ||
}, | ||
{ | ||
"path": "basic_syntax/expressions", | ||
"title": "Expressions" | ||
}, | ||
{ | ||
"path": "basic_syntax/variables", | ||
"title": "Variables" | ||
}, | ||
{ | ||
"path": "basic_syntax/conditions", | ||
"title": "Conditions" | ||
}, | ||
{ | ||
"path": "basic_syntax/commands", | ||
"title": "Commands" | ||
}, | ||
{ | ||
"path": "basic_syntax/arrays", | ||
"title": "Arrays" | ||
}, | ||
{ | ||
"path": "basic_syntax/loops", | ||
"title": "Loops" | ||
}, | ||
{ | ||
"path": "basic_syntax/functions", | ||
"title": "Functions" | ||
}, | ||
{ | ||
"path": "basic_syntax/importing", | ||
"title": "Importing" | ||
} | ||
] | ||
}, | ||
{ | ||
"path": "advanced_syntax/advanced_syntax", | ||
"title": "Advanced Syntax", | ||
"docs": [ | ||
{ | ||
"path": "advanced_syntax/as_cast", | ||
"title": "As Cast" | ||
}, | ||
{ | ||
"path": "advanced_syntax/nameof", | ||
"title": "Nameof" | ||
"path": "basic_syntax/basic_syntax", | ||
"title": "Basic Syntax", | ||
"docs": [ | ||
{ | ||
"path": "basic_syntax/data_types", | ||
"title": "Data Types" | ||
}, | ||
{ | ||
"path": "basic_syntax/expressions", | ||
"title": "Expressions" | ||
}, | ||
{ | ||
"path": "basic_syntax/variables", | ||
"title": "Variables" | ||
}, | ||
{ | ||
"path": "basic_syntax/conditions", | ||
"title": "Conditions" | ||
}, | ||
{ | ||
"path": "basic_syntax/commands", | ||
"title": "Commands" | ||
}, | ||
{ | ||
"path": "basic_syntax/arrays", | ||
"title": "Arrays" | ||
}, | ||
{ | ||
"path": "basic_syntax/loops", | ||
"title": "Loops" | ||
}, | ||
{ | ||
"path": "basic_syntax/functions", | ||
"title": "Functions" | ||
}, | ||
{ | ||
"path": "basic_syntax/importing", | ||
"title": "Importing" | ||
} | ||
] | ||
}, | ||
{ | ||
"path": "advanced_syntax/type_condition", | ||
"title": "Type Condition" | ||
"path": "advanced_syntax/advanced_syntax", | ||
"title": "Advanced Syntax", | ||
"docs": [ | ||
{ | ||
"path": "advanced_syntax/as_cast", | ||
"title": "As Cast" | ||
}, | ||
{ | ||
"path": "advanced_syntax/nameof", | ||
"title": "Nameof" | ||
}, | ||
{ | ||
"path": "advanced_syntax/type_condition", | ||
"title": "Type Condition" | ||
}, | ||
{ | ||
"path": "advanced_syntax/compiler_flags", | ||
"title": "Compiler Flags" | ||
} | ||
] | ||
}, | ||
{ | ||
"path": "advanced_syntax/compiler_flags", | ||
"title": "Compiler Flags" | ||
"path": "by_example/examples", | ||
"title": "Amber by Example", | ||
"docs": [ | ||
{ | ||
"path": "by_example/ubuntu_updater", | ||
"title": "Ubuntu Updater" | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"path": "by_example/examples", | ||
"title": "Examples" | ||
} | ||
] | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters