Space in PATH variable

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Space in PATH variable
# 1  
Old 07-03-2017
Space in PATH variable

Hi All,
I did a review of some threads to see if someone had come across this problem.

My system is an oracle virtual box solaris 10 installed on a windows 10 system.

Right now I am learning scripting and am just playing with the env variables.

I am trying to update the PATH to read from the oratab file and use it.

My problem: The result I get is not quite right in the little bash statement I had written. My new exported $PATH is echo'd and a space appears between the root path and the oracle path.

My oratab in /var/opt/oracle/oratab reads the following:
Code:
  
 SGCD:/export/home/oracle/app/oracle/product/12.1.0/dbhome_2:N

Since my oracle profile reads ..../dbhome_1 I changed the "1" to a "2" in the oratab file here so as not to get both confused and to see which one is
actually getting copied. I am just learning this bash scripting.

The oracle env path is the following at the env cmd:
Code:
  
 PATH=/usr/bin:/bin:/export/home/oracle/app/oracle/product/12.1.0/dbhome_1/b

in and I am using the following command to cut it from the oratab file:
Code:
 
 ORACLE_HOME=`cat /var/opt/oracle/oratab|grep -v "^#"|cut -d ':' -f2`

output:
Code:
 /export/home/oracle/app/oracle/product/12.1.0/dbhome_2

The result I get is not quite right in the little bash statement I had written.

My new exported $PATH (PATH=/usr/sbin/usr/bin:$ORACLE_HOME/bin) is echo'd and a space appears between the root path and the oracle path right afterthe colon.

output:
Code:
 
 echo $PATH

 /usr/bin:/usr/sbin: /export/home/oracle/app/oracle/product/12.1.0/dbhome_2/bin

For the life of me I cannot figure out why this space appears above because it does not allow for other sql commands to be found and executed in my script.

Eventually i will add this to a loop statement to go thru the entire oratab file.

Any help would be appreciated.

Thanks in advance.

Last edited by rbatte1; 07-04-2017 at 12:32 PM.. Reason: code tags...
# 2  
Old 07-03-2017
What editor are you using?
I tested your code on a AIX ( sorry that is all I have at the moment...) with ksh and cant recreate your issue... So to me nothing is wrong with your code unless there are some unprintable char ( which is often the case with files from windows... )
# 3  
Old 07-03-2017
I am using the vi editor. thanks for your response.
# 4  
Old 07-03-2017
What output do you get from the command:
Code:
grep -v "^#" /var/opt/oracle/oratab|od -bc

?
# 5  
Old 07-04-2017
Not ignoring what Don has said (because that is very important), would you not be better using the IFS variable? The Input Field Separator (I think) is a way to chop up input in a more meaningful way to you, so you could perhaps:-
Code:
IFS=: read SID ORACLE_HOME YorN < <(grep -E "^SGCD:" /etc/oratab)

This should work in bash, but sadly I don't have a true ksh any more. The IFS setting as a colon : means that the output from the grep will be split up and you can read them into three variables, so you get the SID, the ORACLE_HOME that you really want and the Y or N value for it being auto-started. The variables you read are positional and the last variable gets everything to the end of the line, so if you miss out the YorN one, then $ORACLE_HOME
will be /export/home/oracle/app/oracle/product/12.1.0/dbhome_2:N which I assume you do not want.

In ksh, you might have to do this instead (untested) to get a similar result:-
Code:
grep -E "^SGCD:" /etc/oratab | read SID ORACLE_HOME YorN



I hope that this helps,
Robin
# 6  
Old 07-05-2017
Good Morning Don,

Hope you had a nice 4th of July.

Here is the output that I found. It is a bit unusual.

Code:
 $ grep -v "^#" /var/opt/oracle/oratab|od -bc
0000000 012 012 012 012 104 103 107 123 072 057 145 170 160 157 162 164
          \n  \n  \n  \n   D   C   G   S   :   /   e   x   p   o   r   t
0000020 057 150 157 155 145 057 157 162 141 143 154 145 057 141 160 160
           /   h   o   m   e   /   o   r   a   c   l   e   /   a   p   p
0000040 057 157 162 141 143 154 145 057 160 162 157 144 165 143 164 057
           /   o   r   a   c   l   e   /   p   r   o   d   u   c   t   /
0000060 061 062 056 061 056 060 057 144 142 150 157 155 145 137 062 072
           1   2   .   1   .   0   /   d   b   h   o   m   e   _   2   :
0000100 116 040 040 040 040 040 012
           N                      \n
0000107

Regards

al

Moderator's Comments:
Mod Comment edit by bakunin: please use CODE-tags as requested by the forum rules. The rule is there because it enhances readability. Thank you.

Last edited by bakunin; 07-05-2017 at 08:27 AM..
# 7  
Old 07-05-2017
Now I see:
your grep -v "^#" finds the empty lines!
Use grep '^[^#]' instead, or even more precise, grep '^DCGS:'
And without the useless cat
Code:
ORACLE_HOME=`grep '^DCGS:' /var/opt/oracle/oratab | cut -d ':' -f2`

This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Find command fails when a space is in the directory path variable

I have a script like this running under OS X 10.8. The problem arises when the find command encounters a space in the path name. I need the "dir" variable as I'll be extending the script to more general use. #!/bin/bash CFS=$IFS IFS=$(echo) set dir = "/Users/apta/Library/Mail\... (3 Replies)
Discussion started by: apta
3 Replies

2. Shell Programming and Scripting

Setting path variable with a space.

Hi I am using MKS Toolkit c shell. I am trying to set a path variable something like c:/Program Files/blah/blah so set path=(c:/Program Files/blah/blah) this, however, does not work as it splits this thing up into 'c:/Program' and 'Files/blah/blah'. Does anyone have any ideas on... (9 Replies)
Discussion started by: vas28r13
9 Replies

3. Shell Programming and Scripting

Path a variable to sed that includes a path

Hi I'm trying to select text between two lines, I'm using sed to to this, but I need to pass variables to it. For example start="BEGIN /home/mavkoup/data" end="END" sed -n -e '/${start}/,/${end}/g' doesn't work. I've tried double quotes as well. I think there's a problem with the / in the... (4 Replies)
Discussion started by: mavkoup
4 Replies

4. Shell Programming and Scripting

Appending a path in user's PATH variable

Hello Folks, I want to append a path in user's PATH variable which should be available in current session. Background Numerous persons will run a utility. Aim is to add the absolute path of the utility the first time it runs so that next runs have the PATH in env & users can directly run... (6 Replies)
Discussion started by: vibhor_agarwali
6 Replies

5. Shell Programming and Scripting

one liner to extract path from PATH variable

Hi, Could anyone help me in writing a single line code by either using (sed, awk, perl or whatever) to extract a specific path from the PATH environment variable? for eg: suppose the PATH is being set as follows PATH=/usr/bin/:/usr/local/bin:/bin:/usr/sbin:/usr/bin/java:/usr/bin/perl3.4 ... (2 Replies)
Discussion started by: royalibrahim
2 Replies

6. Shell Programming and Scripting

remove a path from PATH environment variable

Hi I need a script which will remove a path from PATH environment variable. For example $echo PATH /usr/local/bin:/usr/bin:test/rmve:/usr/games $echo rmv test/rmve Here I need a shell script which will remove rmv path (test/rmve) from PATH... (9 Replies)
Discussion started by: madhu84
9 Replies

7. Shell Programming and Scripting

Need to execute a command on a path with a space in it...

Hello, I need to execute the following command in a script: /usr/bin/ssh 205.21.1.1 vmware-cmd -v /home/virtual machines//Machine.vmx"createsnapshot Weekly_Backup >/dev/null 2>&1 The problem is that there is a space between virtual and machines and when I run the script I get no such... (2 Replies)
Discussion started by: mojoman
2 Replies

8. Shell Programming and Scripting

sftp how to deal with space in path to dir?

OK I am trying to use something similar to this: #!/bin/sh echo "OK, starting now..." sftp -b /dev/fd/0 user@remotehost <<EOF cd pub ascii put filename.txt bye EOF only difference is the dir I need to cd to has a space in it like this /Import/Server/Prospect File ,... (3 Replies)
Discussion started by: NewSolarisAdmin
3 Replies

9. Shell Programming and Scripting

Problems with Space at path

Hi everyone, I create script for seaching count of differrent file types at my FS. My script: #! /bin/sh #OLD_IFS=$IFS #export IFS=$(echo "\n\t ") echo "Wait a minute... Seaching is performed" d=0;b=0;c=0;p=0;s=0;l=0;f=0 non=0 for fl in $(find /opt/google/picasa/3.0/wine/drive_c... (8 Replies)
Discussion started by: babi4
8 Replies

10. Shell Programming and Scripting

Sed variable substitution when variable constructed of a directory path

Hello, i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem. my var1 is a string constructed like this: filename1 filerev1 filepath1 my var2 is another string constructed like this: filename2 filerev2 filepath2 when i do... (2 Replies)
Discussion started by: alrinno
2 Replies
Login or Register to Ask a Question