0

Below are two similar codes, why the first one is working but not the 2nd one please? Can anyone please explain the usage of curly brackets after the round brackets?

$ vi varoutput.bt
query_td () {
bteq << EOBTQ |grep '^>' |sed -e "s/^>//"
.LOGON TDPROD/userid,pass;
select top 3  '>'||t.cal_dt from rldmprod_v.cal_dt t where t.cal_dt =    current_date;
.LOGOFF;
.QUIT;
EOBTQ
}
var=$(query_td)
echo $var

$ ksh varoutput.bt
2017/05/14

$ vi testoutput4.bt
testabcd=$(bteq <<EOF |grep '^>' |sed -e "s/^>//"
.LOGON TDPROD/userid,pass;

select top 3  '>'||t.cal_dt from rldmprod_v.cal_dt t where t.cal_dt =   current_date;

.LOGOFF;
.QUIT;
EOF)
var=$testabcd
echo $var

$ ksh testoutput4.bt
 *** Failure 5628 Column > not found in rldmprod_v.t.
            Statement# 1, Info =0
  • 2
    The EOF in the second code should be on a line by itself (i.e. not EOF)). – Kusalananda May 14 '17 at 15:59
1

The terminator of end of inline block (EOF in your case) must be the only string in the line. And your script should be rewrite on this manner:

testabcd=$(bteq <<EOF |grep '^>' |sed -e "s/^>//"
.LOGON TDPROD/userid,pass;

select top 3  '>'||t.cal_dt from rldmprod_v.cal_dt t where t.cal_dt =   current_date;

.LOGOFF;
.QUIT;
EOF
)
var=$testabcd
echo $var

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.