Skip to content

Commit 2b41b97

Browse files
committed
Init
0 parents  commit 2b41b97

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Diff for: README.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# bash-types
2+
3+
Types for bash.
4+
5+
Is it safe? No.
6+
Is it fast? No.
7+
Is it stable? No.
8+
Is it smart? No.
9+
10+
Does it work? ... kinda actually
11+
12+
```bash
13+
source bash-types.sh
14+
15+
int a=2
16+
17+
echo "$a" # => 2
18+
19+
int b=foo # => Error: int b assigned to non numeric value 'foo'
20+
```

Diff for: bash-types.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
int() {
4+
local var="$1"
5+
local val
6+
eval "$*"
7+
var="${var%%=*}"
8+
val="$(eval "echo \$$var")"
9+
if [[ "$val" =~ ^[0-9]+$ ]]
10+
then
11+
return
12+
fi
13+
echo "Error: int $var assigned to non numeric value '$val'"
14+
exit 1
15+
}
16+
17+
int a=2
18+
19+
echo "$a" # => 2
20+
21+
int b=foo # => Error: int b assigned to non numeric value 'foo'
22+

0 commit comments

Comments
 (0)