help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variable for directory in cd


From: David Grundberg
Subject: Re: variable for directory in cd
Date: Tue, 09 Mar 2010 20:38:02 +0100
User-agent: Thunderbird 2.0.0.23 (X11/20090817)

Blitz skrev:
I'm trying to use the UNIX command "cd" to jump in and out of directories
programmatically in Octave.  How do I use my variable in the cd command?

trying...

dirs = ls -d */
for j = 1:length(dirs(:,1)),
     cd dirs(j,:)   % line I'm having trouble with
     % do stuff
     cd ..
end

I'm running Octave 3.0.1 under Ubuntu

thanks!

You're calling cd with command call syntax. Can't reference variables then. You have to use expression statements if you want to use variable values.

So you're doing

   cd dirs(j,:)

which is evaluated as

   cd ("dirs(j,:)")

which won't work. You have to do it like this:

   cd (dirs(j, :))

Also, I'd recommend from moving away from

   dirs = ls -d */

and using

   dirs = dir ();

with extra logic instead. Return values from command calls aren't supported in 3.2 IIRC.

hth,
David


reply via email to

[Prev in Thread] Current Thread [Next in Thread]