Search code examples
rbashlittler

Third littler example/littler script --how do you run it?


So, I'm trying to reproduce the example here

So the first three examples:

echo 'cat(pi^2,"\n")' | r

and

r -e 'cat(pi^2, "\n")'

and

ls -l /boot | awk '!/^total/ {print $5}' | \
             r -e 'fsizes <- as.integer(readLines());
                print(summary(fsizes)); stem(fsizes)'

work great. The third one:

$ cat examples/fsizes.r
        #!/usr/bin/env r

        fsizes <- as.integer(readLines())
        print(summary(fsizes))
        stem(fsizes)

How do you run this? Sorry for the dumb question I am no bash guru...


Solution

  • If the file is in examples/fsizes.r, then make it executable:

    chmod +x examples/fsizes.r
    

    And then run it with:

    ./examples/fsizes.r
    

    The script expects input, one integer per line. When you run it, you can enter line by line, and press control-d to end the input. Or, you can create a file with numbers, and use input redirection, for example:

    ./examples/fsizes.r < input.txt