Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'General usage' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
General usage
Authored by: SOX on Mar 11, '05 04:58:32PM

As a number of people have pointed out, perl and python have standard input modes that permit a simpler version of the hint to exist. However the general principle of the hint works for any language (octave, r, bash, ruby...) that can execute a temporary file.

The guts of the script contains just four simple elements. Capturing a standard input stream, reformatting carriage returns to linefeeds, generating a uinquely named temporary file. Then it executes this file and
prints the results to the standard error.

So in principle executing the file using any command language is only a change of the command name needed to run the language of choice.

Note there is one non-obvious flourish. The command prints the the Standard input back to the strandard output and it sends all other text to the standard error. Both of these steps are critical if you want to use it as a filter and not simply run it at the command prompt. For example in bbedit if you were to not print out the text that was read in then when run as a filter it would delete your selected text! If the output were sent to the STDOUT rather than the standard error then in filter mode in bbedit it would append the error messages and output text to the slected text in your editor window.

For bash, perl and python, and using a terminal window as was pointed out this script is not needed since one can do:
pbpaste | perl -w
or
pbpaste | pthyon
or, for any shell language, just
pbpaste


but for other less convenient command interpreters this script is needed.

for bbedit the unix_script file could be simplified to
#!/usr/bin/sh
pbpaste | perl -w

the only difference between the above and the script I provided is that now you have to copy the text in bbedit, not just select it, so that it is placed in the pasteboard. And you also have to make sure you run it as a bbedit unix_script and not as a Unix_filter to avoid deleting your original text since the above script does not echo the original text back.




[ Reply to This | # ]