Eve Commands
System variables
System variables start with prefix $. You can export Eve shared variables to the operating system using "export" command. When you work with files and folders, the system security is effective. You can't access the folders or the files over which you have no user rights.
These are several system variables available by default in Eve. These change automatically sometimes as an effect of the commands.
- $CWD = is the current working folder;
- $HOME = is the user home directory;
All the system variables are listed in System Variables.
Shell command
The call keyword sends a command to the operating system and executes a native kernel command.
Shell syntax
call [input +>] command [+> output]
command ::= "os_command -flags {value} {value} ..."
os_command::= {ls, cd, rm, chmod, ...}
Note: The shell commands are string literals or variables. Binding Eve variables to OS command is using string interpolation. That means you can use placeholders such as {name} in the command string; a literal brace is \{ or \}.
Using call
Call is useful to execute an OS shell script (.sh) or a OS commands, usually this will produce an output to console. The output can be redirected to a file or piped to another command.
capture output
You can capture the output as a list of strings using operator +>. In next example we capture a list of files
# listing files in folder "test"
primary aspect shell_output is
set files: ()String;
process main is
call "cd {$HOME}/test";
call "ls -l *.dat" +> files;
loop
new file: String;
for file in files do
print file;
done;
return;
end shell_output;
accept input
# execute a shell script
primary aspect shell_input is
set files: ()String;
process main is
call "cd {$HOME}/test";
call ("hello", "world") +> "./shell_test.sh";
return;
end shell_input;
The input must be accepted by the script using "read".
#!/bin/bash
while read line
do
echo $line
done < /dev/stdin
Programs without a shell: os.run
At level 5 the module os starts a program from an argument list, without a shell: there is no quoting problem and no injection. call stays for a whole command line.
new r := os.run("git", ("status", "--short"), cwd: "work");
print "exit {r.code}";
print r.out;
os.run(command, arguments, cwd: dir) gives a record {code: Integer, out: String, err: String}. Use it whenever the arguments are built from data, as in an ETL job that calls a compressor or a loader. The database administration commands (db list, db sql, db describe, db migrate, db validate) are machine commands; see Databases.
Using classes
Eve is using classes that simulate the operating system functionality. These classes are not yet designed. These system classes are loaded automatically, you do not have to import anything when you use them.
Example:
The next example demonstrates how to use class Files to read a directory for files. Notice we do not use shell command to do it, we simply create a list of files.
# listing files in folder "test"
primary aspect folder_test is
set files: ()File;
set folder: Folder;
process main is
let folder := Folder($HOME/"test");
loop
new file: File;
for file in folder.files() do
print file.name;
done;
return;
end folder_test;
Read next: EveDB