-1

I'm using Linux 2.6.x.x.x
SUSE Linux Enterprise Server 10 (i586)

The question I want to know is how to pass a value through a pipe to a command ??
On every other operating system, including DOS, I can use:

echo <value> | <command>

But on Linux, this does not seem to work.

For example, I want to pass a Database Name to an Oracle command that sets Environment Variables for the Database based on what it reads from the oratab file.

Normally, the command would run as:

 . oraenv   (to source environment variable settings)

Then, it would prompt you for the Database Name.

But, if I run: echo <some_db_name> | . oraenv , it works without prompting and is useful in scripts on every platform except this version of Linux.

Any ideas?

$ <> /home/oracle>echo $SHELL   
/bin/bash
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Ji Li
  • 1
  • 1
  • 1

3 Answers3

3

On Unix, the pipe is used to pass the output of a program in the input of another.

ex:

$ echo "b c a e d" | tr " " "\n" | sort 
a
b
c
d
e

From http://www.orafaq.com/wiki/Oraenv

Non-interactive (handy for scripting):

$ export ORACLE_SID=orcl
$ export ORAENV_ASK=NO
$ . oraenv
ablm
  • 1,265
  • 10
  • 19
1

Did you already tried something like this?:

echo "table" | ./oraenv -

Where "-" means /dev/stdin

hecky
  • 11
  • 1
0

So if I understand you correctly, you want to set the user profile. Usually, Environment variables are EXPORTED inside a profile file. But if you want to build your own profile file you can ask the user for values , like

echo "Enter the DB Name:"    #This is optional but can be used in case if someone runs the script like $ . ./oraenv
read ORACLE_SID    # ORCL_SID is a variable
. oraenv

Once you place something like above in oraenv the command echo <db name>|. ./oraenv should work.Another method would be use command line arguments like

if [ $# -lt 1 ]             # $# is the number of arguments passed to the script
then
    echo "DB Name must be entered"
    exit 0
else
    ORACLE_SID =$1             # initialize $1 is the first arg which is the db name, consecutive args can be accessed by $2, $3 and so on.
    . oraenv
fi

Once you have the above, the command below should work.

$ . ./oraenv oradev

Having said all this, the oraenv utility is an Oracle utility and you wouldn't be able to edit or modify that utility. So the best way to go with that is EXPORTING the variables before running oraenv, the solution above would be applicable for a custom oraenv script (if you wish to write one).

Anjan Biswas
  • 7,746
  • 5
  • 47
  • 77