59 lines
No EOL
1.4 KiB
Markdown
59 lines
No EOL
1.4 KiB
Markdown
amber bash
|
|
|
|
https://docs.amber-lang.com/getting_started/getting_started
|
|
|
|
**installation**
|
|
download its release and add binary to PATH env variable
|
|
|
|
**usage**
|
|
`amber run main.ab` to simply run it
|
|
|
|
`amber build main.ab main.sh` to convert it into bash script
|
|
`./main.sh`
|
|
|
|
**example**
|
|
|
|
```js
|
|
// importing inbuilt methods for array and text variables
|
|
import { split, slice } from "std/text"
|
|
|
|
const reduceFactor = 10
|
|
|
|
// this main function allows using arguments
|
|
main(args){
|
|
|
|
echo(args[1])
|
|
|
|
// accepting first argument as folder. index 0 is just main.ab or bash
|
|
const folder = args[1]
|
|
|
|
|
|
// using commands and getting its output into text variable named 'res'
|
|
let filesSortedByTimeStr = $ ls -t "{folder}" $ failed {echo(-1)}
|
|
|
|
// converting string to array with demiliter
|
|
let filesSortedByTimeArray = split(filesSortedByTimeStr, "\n")
|
|
|
|
let abFilesSortedByTimeArray = []
|
|
for index,file in filesSortedByTimeArray{
|
|
|
|
if slice(file, -4) == ".fos" {
|
|
// add elements into array
|
|
abFilesSortedByTimeArray+=[file]
|
|
|
|
}
|
|
}
|
|
|
|
const bufferFolder = "{folder}/tobedeleted"
|
|
$ mkdir -p "{bufferFolder}" $ failed {echo("couldnt created tobedeleted folder")}
|
|
for index,file in abFilesSortedByTimeArray{
|
|
if index % reduceFactor != 0{
|
|
$ mv "{folder}/{file}" "{bufferFolder}/" $ failed {}
|
|
}
|
|
}
|
|
|
|
let res = abFilesSortedByTimeArray
|
|
$ echo {res} > output.txt $ failed{}
|
|
}
|
|
|
|
``` |