You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The "test" command evaluates a conditional expression. It is an if statement that will return zero (true) or 1 (false), or greater than 1 (error).
Approach
The "test" command will check if any flags were inputted and, based on the expression, will return a truthy or falsy value. For example,test -e myfile.txt will return 0 if that file exists. Will have to use the sys_fstat to obtain information about the specified file.
Files to be Modified/Added
user:
user.h (add test)
test.c (new: call sys_open, pass a path to that and that will give us a file descriptor. With the file descriptor we call sys_fstat, and pass in an file descriptor, and a pointer to an empty stat struct which is an output, it is going to modify it)
Subcommands Implemented in Test
Command
Description
-d file
True if file exists and is a directory.
-e file
True if file exists (regardless of type).
-f file
True if file exists and is a regular file.
file1 -ef file2
True if file1 and file2 exist and refer to the same file.
s1 = s2
True if the strings s1 and s2 are identical.
s1 != s2
True if the strings s1 and s2 are not identical.
n1 -gt n2
True if the integer n1 is algebraically greater than the integer n2.
n1 -lt n2
True if the integer n1 is algebraically less than the integer n2.
Future Development
Add functionality for more flags
Add logical operators for combining expressions
Edit sh so that test can be incorporated in shell scripting
This sounds like a good project, although I don't think there is any reason to modify kernel space. The stat system call should already be enough for getting file system information. When you get a chance, can you specify the exact test features you plan to implement?
test
The "test" command evaluates a conditional expression. It is an if statement that will return zero (true) or 1 (false), or greater than 1 (error).Approach
The "test" command will check if any flags were inputted and, based on the expression, will return a truthy or falsy value. For example,
test -e myfile.txt
will return 0 if that file exists. Will have to use the sys_fstat to obtain information about the specified file.Files to be Modified/Added
user:
Subcommands Implemented in Test
Future Development
Add functionality for more flags
Add logical operators for combining expressions
Edit sh so that test can be incorporated in shell scripting
References
man test
The text was updated successfully, but these errors were encountered: