rush is an ruby-shell designed for command-line tasks such as file and process handling.
In lieu of bash command sequence joined by pipes, you subsequently apply methods or refere to members on the object yielded before. The following example start with a filtered list of the files in the directory
This has several advantages:
* Presuming you are in ruby you can fully use your ruby tools-set.
* You can do one-liners subsequently processing arbitrary objects.
* For more complex cases you have a descent programming language at hand.
There are downsides:
* In order to call other system commands you have use bash-wrapper command.
* The project does seem to be maintained at the moment and there is very little documentation. The above example, though taken from the projects home page, does not seem ro work.
It is a good approach to start with reasonable programming language and then make some alternations in order to get a useful shell. Maybe ruby is not the very best choice as base language because it has a bit particular syntax that might be unnecessarily confusing to non-expert users.
return statement is for passing a return code, e.g. number between 0 and 255. If you want to output a string you have to do a
echo within the function body. There are two issues with that.
First, you cannot distinguish between the output the function returns and some information you want to print for instance for debugging while the body is executed.
Assume a function
list_certain_pdfs that computes a list of all pdf-files that contain a certain string and can be found below a base-directory passed as input.
For each directory below the base-dir that contain at least one fitting pdf the function should also print the number of found pdfs to stdout while running.
This should not be difficult to do, but with bash it is.
Second, it is not clear how pass an array as output of a function. As we already know, structured data types do not belong to bashs assets. One reason arrays are rarely used might be that you cannot simply return them from a functions body.
A way to deal with the situation is pointed out here. It is a valid solution but it is also a kludge.