shell - 无法在脚本中打印 shell 命令的结果
问题描述
我发现这篇关于如何从 DOCX 文件中提取文本的有用帖子,我想把它变成一个小 shell 脚本。我的尝试如下
#!/bin/sh
if [[ $# -eq 0 ]]; then
echo "pass in a docx file to get the text within"
exit 1
fi
text="$(unzip -p $1 word/document.xml | sed -e 's/<\/w:p>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g')"
echo $text
但是,这不会按预期打印结果。
有什么建议么?
解决方案
感谢shellcheck.net,我发现我需要在$1
. 经 shellcheck 批准的最终脚本是:
#!/bin/sh
if [ $# -eq 0 ]; then
echo "pass in a docx file to get the text within"
exit 1
fi
text=$(unzip -p "$1" word/document.xml | sed -e 's/<\/w:p>/\n/g; s/<[^>]\{1,\}>//g; s/[^[:print:]\n]\{1,\}//g')
echo "$text"
推荐阅读
- android - 如何在 PWA Android 应用中隐藏 URL 栏?
- android - 无法在 android studio 中运行构建/运行任何项目。错误:进程意外退出
- sql - Informix SQL 查询在特定范围内的日期进行连接
- java - 如何修复“无法访问主线程上的数据库,因为它可能会长时间锁定 UI。”
- javascript - 店面功能未正确输出
- latex - 带有人物符号的 LaTeX 投影仪幻灯片
- java - 我想知道为什么这个结果不是 1000000
- php - Laravel: Eloquent Querybuilder whereTimestamp?
- go - 允许超过 content-type: application/json in gorilla
- java - 没有约束异常处理的休眠线程安全幂等插入?