[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Linux environment variable question
From: |
Dupuis |
Subject: |
Re: Linux environment variable question |
Date: |
Wed, 3 Feb 2010 08:00:25 -0800 (PST) |
David Aldrich-2 wrote:
>
> Hi
>
> I need to run a function under Octave that requiries two filenames as
> parameters. The parameters must be full paths, but the paths are long, so
> I want to specify part of the path by an environment variable. However, I
> can't get the syntax right. Here is what I do:
>
> $ mypath = 'home/myname'
>
> $ octave -q --eval "fprintf('%x', RegressionTest($mypath + 'filename1',
> $mypath + 'filename2'))"
>
> but this gives a syntax error in the path.
>
> What would be correct syntax please?
>
>
If you really need to access an environment variable from inside , getenv()
is the answer. In your case, the problem is at shell expansion rules. On my
machine, I tried
export MYPATH=toto
echo octave -q --eval "fprintf('%x', RegressionTest($MYPATH 'filename1',
$MYPATH 'filename2'))"
to obtain
octave -q --eval fprintf('%x', RegressionTest(toto 'filename1', toto
'filename2'))
This doesn't work, because 'toto' is interpreted as a variable name
The solution is
echo octave -q --eval "fprintf('%x', RegressionTest('$MYPATH/filename1',
'$MYPATH/filename2'))"
to get
octave -q --eval fprintf('%x', RegressionTest('toto/filename1',
'toto/filename2'))
your two errors where
1) mypath=something doesn't make the environenment variable available for
next commands, 'export' is required.
2) string1 + string2 doesn't create a valid path name : if you need to
concatenate a dir name and a file name inside octave, use filesep() for a
portable way of doing this.
Regards
Pascal
--
View this message in context:
http://old.nabble.com/Linux-environment-variable-question-tp27437060p27438730.html
Sent from the Octave - General mailing list archive at Nabble.com.