spec

Software for Diffraction

2.4.1.1. - System Functions



chdir()
Changes spec's current working directory to to the user's home directory as obtained from the user's environment variable HOME. Returns true or false according to whether the command was successful or not. The value of the built-in string variable CWD is updated to the current working directory.

chdir(directory)
As above, but changes to the directory directory, which must be a string constant or expression.

unix()
Spawns an interactive subshell using the program obtained from the user's environment variable SHELL (or shell). Uses /bin/sh if the environment variable is not set. Returns the integer exit status of the shell.

unix(command)
As above, but uses /bin/sh to execute the one-line command command, which must be a string constant or expression. Returns the integer exit status of the command.

unix(command, str [, len ])
As above, but the argument str is the name of a variable in which to place the string output from the command in the first argument. The maximum length of the string is 4096 bytes (including a null byte). The optional third argument can be used to specify a larger size.

time()
Returns the current epoch in seconds. The UNIX epoch is the number of seconds from January 1, 1970, 00:00:00 GMT. The value returned includes a fractional part with microsecond resolution as provided by the host gettimeofday() system call.

date()
Returns a string containing the current date as
Tue Feb  7 21:02:23 EST 2017


date(fmt)
As above, but the output string is formatted according to the specifications in the string fmt. The format is passed to the standard C library strftime() function (see the strftime man page) with one addition: spec fills in the format options %.1 through %.9 with the fractional seconds, where the single digit specifies the number of decimal digits. For example,
print date("%m-%d-%Y %T.%.6")
would display
02-07-2017 21:04:57.927905


date(seconds [, fmt)
As above, but the returned string represents the epoch given by seconds. See time() above.

getenv(string)
Returns the value of the environment variable represented by the string string. If the environment variable is unset, the null string is returned. Environment variables are exported to spec by the invoking shell program.

file_info(filename [, cmd ])
Returns information on the file or device named filename. With a single filename argument, file_info() returns true if the file or device exists. If the argument filename is the string "?", the possible values for cmd are listed. If filename is the string ".", spec uses the information from the last stat() system call made using the previous argument for filename, avoiding the overhead associated with an additional system call.

Possible values for cmd and the information returned follow. Note that the first set of commands parallel the contents of the data structure returned by the stat() system call, while the second set of commands mimic the arguments to the test utility available in the shell.


"dev"
The device number on which filename resides.

"ino"
The inode number of filename.

"mode"
A number coding the access modes and file attributes.

"nlink"
The number of hard links for filename.

"uid"
The user id of the owner.

"gid"
The group id of the owner.

"rdev"
The device ID if filename is a block or character device.

"size"
The size in bytes of filename.

"atime"
The time when filename's data was last accessed.

"mtime"
The time when filenames's data was last modified.

"ctime"
The time when filenames's attributes were last modified.

"isreg" or "-f"
Returns true if filename is a regular file.

"isdir" or "-d"
Returns true if filename is a directory.

"ischr" or "-c"
Returns true if filename is a character device.

"isblk" or "-b"
Returns true if filename is a block device.

"islnk" or "-h or @-L"
Returns true if filename is a symbolic link.

"isfifo" or "-p"
Returns true if filename is a named pipe (sometimes called a fifo).

"issock" or "-S"
Returns true if filename is a socket.

"-e"
Returns true if filename exists.

"-s"
Returns true if the size of filename is greater than zero.

"-r"
Returns true if filename is readable.

"-w"
Returns true if filename is writable.

"-x"
Returns true if filename is executable.

"-o"
Returns true if filename is owned by you.

"-G"
Returns true if filename is owned by your group.

"-u"
Returns true if filename is setuid mode.

"-g"
Returns true if filename is setguid mode.

"-k"
Returns true if filename has its sticky bit set.

"lines"
Returns the number of newline characters in the file. If the file does not end with a newline, the count is increased by one.


file_info(pid, "alive")
Return true if the process associated with the process ID pid exists.