From help-octave-request at bevo dot che dot wisc dot edu Thu Jan 15 09:47:39 2004 Subject: Re: alias-like function? From: Avraham Rosenberg To: Geraint Paul Bevan cc: =?ISO-8859-1?Q?S=F8ren_Hauberg?= , help-octave Date: Thu, 15 Jan 2004 17:44:29 +0200 (IST) Thanks a lot. I called myfunction octls to avoid having two executables with the same name and without being aware that the name should be one of the functions, like ls, in which octave calls a bash command. This is actually the main thing: provided that the name is right, the file is executable and is in the exec_path it can do most anything, like this very useful version of ls: !#/bin/sh case in 1) echo Hello world !;; 2) echo Go, take a shower !;; *) echo Shut up, bloody idiot !;; esac And of course, if outside octave it is not in the path, it will not interfere with /bin/ls...There is no need to change the name. Sorry for the waste of bandwidth, but maybe I am not the only confused soul around. Cheers, Avraham On Thu, 15 Jan 2004, Geraint Paul Bevan wrote: > Date: Thu, 15 Jan 2004 09:49:00 +0000 > From: Geraint Paul Bevan > To: Avraham Rosenberg > Cc: "[ISO-8859-1] Søren Hauberg" , > help-octave > Subject: Re: alias-like function? > > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Avraham Rosenberg wrote: > | I read your mail and thought: what I nice trick. > | But when I tried it, octave refused to behave. It complained instead of > | "octlc undefined near line 4 column 1" > | octave 2.1.50 on debian 3.0r1 > | 1028~> EXEC_PATH > | EXEC_PATH = > | > /home/avraham/matcompat/bin::/home/avraham/scripts:/usr/local/MuPaD_200/share/bin:/home/avraham/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games > | > | The script octlc -a copy of the one you posted is in > | /home/avraham/matcompat/bin and it is executable. > | Moreover, while the binary files in the path are recognized by octave, > | it balks at all my scripts (starting with the magic #!/bin/sh > | sequence). > | Any suggestions ? > | Thanks, Avraham > | > > > The problem here is that Octave doesn't usually try to run shell scripts > or other system calls when functions are called. It usually looks for .m > and .oct files; "ls" is a special case. > > If you want the command "octlc" to run a bash shell script in Octave, > the easiest way is to create a wrapper "octlc.m" which uses the "system" > function and to place it in your Octave path: > > > geraint at pavilion:~$ cat bin/octlc > #!/bin/sh > echo Hello World > > geraint at pavilion:~$ cat octlc.m > system("/home/geraint/bin/octlc"); > > geraint at pavilion:~$ octave -q > octave:1> octlc > Hello World > octave:2> > > > Inidentally, the "ls" script I posted before should have had $* at the > end of the command so that ls would continue to accept arguments from > theshell: > > #! /bin/sh > exec /bin/ls --color $* > > > - -- > Geraint Bevan > http://homepage.ntlworld.com/geraint.bevan > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.2.3 (GNU/Linux) > > iEYEARECAAYFAkAGYgwACgkQcXV3N50QmNO/CQCggp/u4P+ozysYLXnOj2GNUtkF > kKwAoInD3c8lZFyDEMiL5lL8Acz8CkDA > =kzgF > -----END PGP SIGNATURE----- > ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------