尝试这个:
#!/bin/bash
DATE_YEST=`TZ=GMT+48 date +%Y%m%d`
echo $DATE_YEST
echo "SELECT * FROM PDS_ATTRIBUTE_DATA_REALTIME WHERE dt=$DATE_YEST"
输出将是:
20120806
SELECT * FROM PDS_ATTRIBUTE_DATA_REALTIME WHERE dt=20120806
如果您需要选择周围的引号,请使用:
#!/bin/bash
DATE_YEST=`TZ=GMT+48 date +%Y%m%d`
echo $DATE_YEST
echo "\"SELECT * FROM PDS_ATTRIBUTE_DATA_REALTIME WHERE dt=$DATE_YEST\""
输出将是:
20120806
"SELECT * FROM PDS_ATTRIBUTE_DATA_REALTIME WHERE dt=20120806"
假设您想要引号,您的脚本将如下所示:
#!/bin/bash
DATE_YEST=`TZ=GMT+48 date +%Y%m%d`
echo $DATE_YEST
hive -S -e "\"SELECT * FROM PDS_ATTRIBUTE_DATA_REALTIME WHERE dt=$DATE_YEST\""