Without knowing anything about Nutshell, guess what the following command outputs:
If you guessed that it displays only those files in the current directory that are less than 2000 bytes in size, that would be correct. But that wasn’t too hard, was it? The syntax is quite intuitive. Now compare it what you would really have to type in bash:
Show this command to a seasoned Unix guru. Even he can’t decipher this command without looking at the output of
ls -l first.
awk command is doing. It is splitting the output of
ls -l ,taking the 5th token of each line, performing the comparison, and printing the whole line if the test succeeds. This is where shell scripting is unproductive. It’s all about parsing output.
So how does Nutshell solve this? By using a technique called object piping. When you type in
ls command outputs an object which looks like this:
All the filter command needs to do is evaluate the function passed to it as an argument, run it over the list, and call the toString over each object. Simple, intuitive and saves a couple of hours of hunting though man pages of awk and find. The aim of Nutshell is to be fully compatible with bash. So you can also use traditional Unix commands in a pipe. Objects are turned into strings by calling their toString methods before being passed to a Unix command. So, you are into command-line masochism, you can write commands like this in Nutshell: