我是shell脚本的新手。我有以下shell脚本-
psql database connection -t -c "SELECT bucket FROM all_buckets GROUP BY bucket" | while read bucket_var ;
do
if [ ! -z "$bucket_var" ]
then
echo "Bucket being processed is - $bucket_var"
fi
done
这是我得到的输出-
+ '[' '!' -z Endography ']'
+ echo 'Bucket being processed is - Endography'
Bucket being processed is - Endography
+ read bucket_name_var
如何得到这个输出-
Bucket being processed is - Endography (current date and time in CST)
看起来您的脚本中有set -x
。这使得它在执行命令时回显所有命令。删除该行(或执行set +x
撤消设置)。
摘自set
的man
页:
-x
在展开每个简单命令(for command、case command、select command、arithmetic for command)后,显示PS4的展开值,后面是该命令及其展开参数或相关的单词列表。
添加当前日期和时间,使用date
:
echo "Bucket being processed is - $bucket_var ($(date))"