PDA

View Full Version : [ubuntu] .bashrc - problem with -p option



perhaugaard
February 27th, 2009, 01:43 PM
Dear users,

I am fairly new to Linux and Ubuntu. I am editing my .bashrc for octave path environment and I have run into a hurdle. I get and error "bash: -p: command not found" on the -p option and I do not know why.

Can anybody figure that out?

octave_config=/opt/octave_v303/bin/octave-config
if [ -f $octave_config ]; then
# -------------------------
# Octave software selection: choose the right octave-config executable
# All configuration information can be obtained from octave-config
# ----------------------
OCTBIN=`$octave_config --print BINDIR`
export PATH=$OCTBIN:$PATH
unset octave_config OCTBIN
alias octave='octave -q'
# ----------------------
export OCTAVE=`$octave_config -p PREFIX`
export OCTVER=`$octave_config -p VERSION`
fi


Best regards

Per Haugaard

lloyd_b
February 27th, 2009, 02:30 PM
A quick guess - it's the single quotes.

In a shell script, arguments such as $OCTAVE are *not* evaluated when enclosed in single quotes. But they *are* evaluated when enclosed in double quotes.

Here's a short script to illustrate the point

#!/bin/bash
TEST="Hello"

echo 'single quotes -> $TEST'
echo "double quotes -> $TEST"and here's the output:
single quotes -> $TEST
double quotes -> Hello

So I think all you need to do is change all those single quotes to double quotes...

Lloyd B.

perhaugaard
February 27th, 2009, 02:43 PM
Dear Lloyd B. and users

Thx, it seems to work. Do I also change the single quootes the line

OCTBIN=`$octave_config --print BINDIR`

to double quotes? or is the matter different here?


/Per

lloyd_b
February 27th, 2009, 03:08 PM
Uh oh - I think I gave you some *wrong* advice. Upon looking more closely at your script, those weren't single quotes, they were "backticks", which is an entirely different animal (enclosing a command in backticks causes the command to be executed, and the output of that command to be stored in the shell variable).

So you'll need to change the script back. Remember to use the backtick rather than the single quote (it's the key right above the TAB key on US keyboards).

The *real* problem is the line "unset octave_config OCTBIN" - this needs to be moved to *after* the "export OCTAVE=..." and "export OCTAVER=..." lines - it's clearing the value of $octave_config", so when those two lines execute $octave_config is evaluated as a NULL.

Sorry for the bad answer - my eyes have problems distinguishing between single quotes and backticks, and I didn't take the time to really understand the script.

Lloyd B.

perhaugaard
February 27th, 2009, 03:25 PM
Hi Lloyd B.,

I was not thinking when I agreed to the single quotes BUT your suggestion to move the unset line to end of the if sentence seems to sort out things with the .bashrc. So this is how the script looks like now:

octave_config=/opt/octave_v303/bin/octave-config
if [ -f $octave_config ]; then
# -------------------------
# Octave software selection: choose the right octave-config executable
# All configuration information can be obtained from octave-config
# ----------------------
OCTBIN=`$octave_config --print BINDIR`
export PATH=$OCTBIN:$PATH
alias octave='octave -q'
# ----------------------
export OCTAVE=`$octave_config -p PREFIX`
export OCTVER=`$octave_config -p VERSION`
unset octave_config OCTBIN
fi


Thank you very much for your help :D


/Per