Obey Files
David Gee (1833) 268 posts |
Can Obey files take parameters on the command line, in the way that DOS Batch files and UNIX shell scripts can? (If so, how?) Can I change the type of a file programmatically (i.e. in an obey file)? And a long shot: in a UNIX shell script I can read the output of a command by surrounding it with backticks (`). Is this possible in RISC OS? Unlikely, I know, but… |
Steve Revill (20) 1361 posts |
Yes. %0 is the first parameter, %1 the second, etc. You’d use %*0 to give you all the parameters as a single string, or %*1 for all but the first, etc. For this reason, you need to use %% to escape a single % sign in an obey file. Unlike shell scripts, there’s no system variable (AFAIAA) that holds the name of the obey file itself. There is, however, Obey$Dir to tell you where the obey file was executed from. Why there isn’t a corresponding Obey$File, I’ve no idea.
SetType
Only in a fairly cludgy way, via redirection of output to a file using curly braces and the greater than sign (use > to write or >> to append). See this post for an example that does most of this. |
Jeffrey Lee (213) 6048 posts |
Yes. The parameters will come through as %0, %1, %2, etc. You can also do things like use %*1 to get all the parameters from %1 and up (useful if you need to pass a bunch of parameters on to another command/tool)
*SetType
Not supported, I’m afraid. But depending on your needs, you can make use of redirection. But be aware that RISC OS does redirection differently than other OS’s; with C programs you can use the standard > and < redirection operators directly, but with arbitrary commands you need to place the redirection operators in {}. E.g. “*echo foo { > temp }” There are basically two tricks I know of for using redirection to process the output of a command:
|
Jeffrey Lee (213) 6048 posts |
Bah, beaten to the post! |
Steve Revill (20) 1361 posts |
:P |
Steve Revill (20) 1361 posts |
Edit: If you’re using the RISC OS Pi distro, you should have a copy of the PRMs on the disc, in Documents.Books.PRMs. The specific chapter you’ll want to see is in PRM4, starting on page 351 (“Command scripts”). |
Steve Drain (222) 1620 posts |
The syntax is ok, but I am not sure that it is at all reliable. I may have some special circumstances on the RISC PC I did the testing on. Do not rely on it, but use the method Jeffrey suggested. |
Steve Revill (20) 1361 posts |
One thing that is miles better in this area on RISC OS when compared to Linux is aliases have parameters, in much the same way as obey files. So your alias can do things like reorder the parameters before passing them on to whatever is aliased. I’m pretty sure you can’t do that in bash, for example. /me waits for someone to prove him wrong. |
David Feugey (2125) 2709 posts |
Don’t forget PipeFS too. |
David Gee (1833) 268 posts |
Perhaps because there’s no obvious need—after all, the file knows what its name is. On UNIX-like systems, with hard links, a file may have several different names. The text editor e3 uses this feature to specify the key mapping—e3ne for NEdit,e3me for MicroEmacs, the default is WordStar (I think). It’s a very nice console-mode text editor, very small, needs no shared libraries, but will never run on RISC OS—it’s written in X86 assembler. |
Steve Revill (20) 1361 posts |
Kind of. Unless you want your obey file to be a template for multiple files, or you have a process which renames/copies it. Then you have to do a search and replace operation within the obey file. Plus, if and when we get symbolic links, we’d just have to add this anyway… :) |