Shell Script, why do i get a space here ?

  • delta32
  • Newbie
  • Newbie
  • delta32
  • Posts: 11

Post 3+ Months Ago

#!/bin/ksh

THIS_DATE=`sqlplus -s / <<eofsql
set pages 0
set head off
select to_char(sysdate,'YYYYMMDD') from dual;
eofsql`

echo date${THIS_DATE}

this gives

date20060131..

but ...
....................
select to_char(sysdate,'YYYYMMDD') -1 from dual; (just gave -1)
....................

gives

date 20060131 ( here there is a space b/w date and the numbers)

can somebody tell me why?
:(
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • GhodMode
  • Novice
  • Novice
  • User avatar
  • Posts: 19
  • Loc: Kota Kinabalu, Sabah, Malaysia

Post 3+ Months Ago

Since to_char() returns a character, rather than a number, it means nothing to subtract 1 from it. I think that what you want looks something like this (note the location of the -1):
Code: [ Select ]
THIS_DATE=`sqlplus -s << ENDSQL
set pages 0
set head off
select to_char( (sysdate - 1), 'YYYYMMDD' ) from dual;
ENDSQL`

echo "date$THIS_DATE"
  1. THIS_DATE=`sqlplus -s << ENDSQL
  2. set pages 0
  3. set head off
  4. select to_char( (sysdate - 1), 'YYYYMMDD' ) from dual;
  5. ENDSQL`
  6. echo "date$THIS_DATE"


I don't know for certain that it's causing the extra space, though. You could remove spaces with tr:
Code: [ Select ]
echo "date$THIS_DATE" | tr -d ' '


I think that was a SQL*Plus question rather than a Unix/Linux question :?

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 66 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.