I am working on a script in KornShell (ksh). My database connection is through SQLPLUS to an Oracle 9i database. I have not had any problems getting DB values into shell variables, EXCEPT that any consecutive whitespace is automatically truncated to only one character.
Here is an example of my code:
MY_VAR=`sqlplus -s usr/pass@db << !
set heading off;
set pagesize 0;
select a_value from a_table where an_index = 25;
!`
The actual data in the database is like this:
Dec 15 09:19:10 <24:0070> User record (5 XATY 41839FG8 58775HK9AFF) is invalid for this condition
My code example above returns it like this:
Dec 15 09:19:10 <24:0070> User record (5 XATY 41839FG8 58775HK9AFF) is invalid for this condition
The spacing is critical for what I am working with.
Thank you in advance for your help.
First off, don’t use backticks, they’re deprecated per ‘The New Kornshell Programming Language’, published 1995! Instead, use the easy-to-nest version of command substitution,
$( yourCmd goes here).You don’t show us how you’re using your variable $MY_VAR. If you saying
You need to quote the variable, i.e.
Printis a ksh major-upgrade on echo, but it is best to have the habit of using ‘–‘ between the command and the strings you want toprint. Any ‘-‘ char in the string you want to print can throw an unguarded (i.e. no ‘–‘),printcommand for a loop.You may also need to quote the assignment to MY_VAR, i.e.
I’ve switched to EOD, as the ! char is used by many shells for notations like !$ (last word of previous line), so why confuse things.
Note for future: There is a tag for ksh that you can use here on StackOverflow. Shell is ver ambiguous, and can mean Windows cmd.com as well as zsh.
I hope this helps.