Skip to content
Snippets Groups Projects
Commit e75283d4 authored by baka's avatar baka
Browse files

manual: Various fixes and improvements

parent 63d1bf76
No related branches found
No related tags found
No related merge requests found
......@@ -68,14 +68,14 @@ DESCRIPTION
With arguments cd changes the working directory to the directory you provided.
```
## contains - check if a given string starts with another one
## contains - check if a given string contains another one
```txt
SYNOPSIS
contains <PATTERN> tests...
DESCRIPTION
Returns 0 if any given argument contains the first argument, else returns 1
Returns 0 if the first argument contains any of the other ones, else returns 1
```
## dir-depth - set the dir stack depth
......@@ -155,14 +155,14 @@ OPTIONS
\v vertical tab (VT)
```
## ends-with - check if a given string starts with another one
## ends-with - check if a given string ends with another one
```txt
SYNOPSIS
ends-with <PATTERN> tests...
DESCRIPTION
Returns 0 if any argument ends with the first argument, else returns 1
Returns 0 if the first argument ends with any of the other ones, else returns 1
```
## eval - evaluates the specified commands
......@@ -436,7 +436,7 @@ SYNOPSIS
starts-with <PATTERN> tests...
DESCRIPTION
Returns 0 if any given argument starts with the first argument, else returns 1
Returns 0 if the first argument starts with any of the other ones, else returns 1
```
## status - Evaluates the current runtime status
......
......@@ -47,7 +47,7 @@ reason for a shell language to have multiple different keywords to end different
## Complete List of Conditional Builtins
- [x] and
- [z] contains
- [x] contains
- [x] exists
- [x] eq
- [ ] intersects
......@@ -59,8 +59,8 @@ reason for a shell language to have multiple different keywords to end different
- [x] test
- [ ] < (Polish Notation)
- [ ] <= (Polish Notation)
- [ ] > (Polish Notation)
- [ ] >= (Polish Notation)
- [ ] &gt; (Polish Notation)
- [ ] &gt;= (Polish Notation)
- [ ] = (Polish Notation)
## Using the **&&** and **||** Operators
......
......@@ -46,10 +46,10 @@ Match guards can be added to a match to employ an additional test
```sh
let foo = bar
match $string
case _; echo "no match found"
case "this" if eq $foo bar
echo "this and foo = bar"
case "this"
echo "this and foo != bar"
case _; echo "no match found"
end
```
......@@ -8,8 +8,8 @@ into an array delimited by whitespaces.
```sh
let string = $(cmd args...)
let array = @(cmd args...)
let array = [ @(cmd args...) ]
```
**NOTES:**
- To split outputs by line, see `@lines($(cmd))`.
- `@(cmd)` is equivalent to `@split($(cmd))`
- To split outputs by line, see [@lines($(cmd))](https://doc.redox-os.org/ion-manual/html/expansions/05-method.html#lines).
- `@(cmd)` is equivalent to [@split($(cmd))](https://doc.redox-os.org/ion-manual/html/expansions/05-method.html#split).
......@@ -18,7 +18,7 @@ string variables. Supported operators are as below:
- Bitwise XOR(`$((a ^ b))`)
- Bitwise AND(`$((a & b))`)
- Bitwise OR(`$((a | b)))`)
- Bitwise NOT(`$(a ~ b))`)
- Bitwise NOT(`$((a ~ b))`)
- Left Shift(`$((a << b))`)
- Right Shift(`$((a >> b))`)
- Parenthesis(`$((4 * (pi * r²)))`)
......
......@@ -49,9 +49,7 @@ echo $len([1 2 3 4 5])
## Method Arguments
Some methods may have their behavior tweaked by supplying some additional arguments. The `@split()`
method, for example, may be optionally supplied a pattern for splitting. At the moment, a comma
is used to specify that arguments are to follow the input, but each argument supplied after that
is space-delimited.
method, for example, may be optionally supplied a pattern for splitting.
```sh
for elem in @split("some space-delimited values"); echo $elem; end
......@@ -256,7 +254,7 @@ with, a new string will be returned with all matches replaced.
```sh
let input = "one two one two"
echo $replace(input, one 1)
echo $replace(input one 1)
echo $replace($replace(input one 1) two 2)
```
......@@ -297,15 +295,15 @@ as a regex.
#### Examples
```sh
echo $regex_replace("FOOBAR" "^F" "f")
echo $regex_replace("FOOBAR" "^f" "F")
echo $regex_replace("bob" "^b" "B")
echo $regex_replace("bob" 'b$' "B")
```
#### Output
```
fOOBAR
FOOBAR
Bob
boB
```
### reverse
......@@ -396,7 +394,7 @@ echo $unescape($line)
### or
Defaults to string variables. Fallback to a given value if the variable is not defined
Defaults to string variables. Fallback to a given value if the variable is not defined or is an empty string.
#### Example
......@@ -428,11 +426,12 @@ The following are the currently-supported array methods.
### lines
Defaults to string variables. The supplied string will be split into one string per line in the input argument.
This is equivalent to `@split(value '\n')`.
#### Examples
```sh
for line in @lines($unescape("first\nsecond\nthird")
for line in @lines($unescape("first\nsecond\nthird"))
echo $line
end
```
......@@ -504,13 +503,13 @@ each byte is displayed as their actual 8-bit number.
#### Examples
```sh
echo @bytes("foobar")
echo @bytes("abc")
```
#### Output
```
102 111 111 98 97 114
97 98 99
```
### chars
......
......@@ -65,7 +65,6 @@ hello John 25 [ coding eating sleeping ]
## Function piping
As with any other statement, you can pipe functions using `read`.
```sh
......@@ -77,6 +76,18 @@ end
echo one two three four five | format_with "-"
```
## Docstrings
Functions can be given a description with the following syntax:
```
fn square x -- Squares a single number
echo $(( x * x ))
end
```
This description is then printed when `fn` is run without arguments.
## Library usage:
When using Ion as a shell library, it is possible you may want to change the builtin functions associated with a Shell.
......
......@@ -93,7 +93,7 @@ ions init file.
# let HISTORY_IGNORE = [ all ] # saved
# let HISTORY_IGNORE = [ whitespace ] # saved
# true # ignored
# let HISTORY_IGNORE = [ ] # saved
# let HISTORY_IGNORE = [ ] # saved
# let HISTORY_IGNORE = [ whitespace ] # ignored
# history
echo @HISTORY_IGNORE
......
......@@ -19,5 +19,5 @@ if test $len(@args) -eq 1
exit
end
echo Arguments: @args[1..]i
echo Arguments: @args[1..]
```
......@@ -2,7 +2,7 @@
Ion supports a universal syntax for slicing strings and arrays. For maximum language support,
strings are sliced and indexed by graphemes. Arrays are sliced and indexed by their elements.
Slicing uses the same **[]** characters as arrays, but the shell can differentiation between
Slicing uses the same **[]** characters as arrays, but the shell can differentiate between
a slice and an array based on the placement of the characters (immediately after an expansion).
**NOTE:** It's important to note that indexes count from 0, as in most other languages.
......@@ -34,7 +34,14 @@ When using inclusive ranges, the end index does not refer to the Nth value, but
```sh
$ let array = [{1...10}]
$ echo @array[1...5]
$ echo @array[0...5]
> 1 2 3 4 5 6
```
The `=` character may be used instead of the third dot.
```sh
$ echo @array[0..=5]
> 1 2 3 4 5 6
```
......@@ -53,7 +60,7 @@ $ echo {10..1}
## Negative Values Supported
Although this will not work for arrays, you may supply negative values with ranges to create
negative values in a range of numbers.i
negative values in a range of numbers.
```sh
$ echo {-10...10}
......@@ -73,9 +80,8 @@ the end index.
```sh
$ echo {0..3...12}
> 0 3 6 9 12
$ echo {1..2..12}
$ echo {0..3..12}
> 0 3 6 9
$ let array = [{1...30}]
```
### Stepping Forward w/ Array Slicing
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment