我知道有 4 个选项
选项 1:分号
echo "put 'test','row1','cf:a','value1'; put 'test','row2','cf:b','value2'; put 'test','row3','cf:c','value3'" | hbase shell -n
选项 2:换行符
echo -e "put 'test','row1','cf:a','value1'\nput 'test','row2','cf:b','value2'\nput 'test','row3','cf:c','value3'" | hbase shell -n
选项 3:执行
exec hbase shell -n << EOF
put 'test', 'row1', 'cf:a', 'value1'
put 'test', 'row2', 'cf:b', 'value2'
put 'test', 'row3', 'cf:c', 'value3'
EOF
选项 4:外部文件
echo "put 'test', 'row1', 'cf:a', 'value1'" > tmpFile
echo "put 'test', 'row2', 'cf:b', 'value2'" >> tmpFile
echo "put 'test', 'row3', 'cf:c', 'value3'" >> tmpFile
hbase shell -n tmpFile
# obviously this also works: cat tmpFile | hbase shell -n
rm tmpFile
是否包含-n
争论取决于你和你的用例。它指示 shell 在第一个失败的命令后停止执行,并以非零退出代码退出。它被添加了HBASE-11658 https://issues.apache.org/jira/browse/HBASE-11658.
我个人更喜欢选项 3,因为它可读并且不需要临时文件。