bash - jenkins bash 脚本 - 从查找命令结果中删除目录路径
问题描述
我需要在我的 dist 目录中搜索 jenkins 中缩小的 .js 和 .css 文件。
我有一个带有 find cmd 的 bash 脚本,如下所示:
for path in $(/usr/bin/find dist/renew-online -maxdepth 1 -name "*.js" -or -name "*.css" -type f); do
# URL of the JavaScript file on the web server
url=$linkTarget/$path
echo "url=$linkTarget/$path"
其中 linkTarget 是:http ://uat.xxxx.com/renew-online 。
我想将 dist/renew-online 形式的缩小文件附加到 linkTarget,例如:
http://uat.xxxx.com/renew-online/main-es2015.cf7da54187dc97781fff.js
但我不断得到:http ://uat.xxxx.com/renew-online/dist/renew-online/main-es2015.cf7da54187dc97781fff.js
我也尝试过 -maxdepth 0 但无法获得正确的网址 - 脚本新手!
希望你们中的一个可以帮助,谢谢你的时间
解决方案
这可以通过仅使用“查找”命令来实现:
/usr/bin/find dist/renew-online -maxdepth 1 \( -name "*.js" -o -name "*.css" \) -type f -printf "$linkTarget/%f\n"
还建议在圆括号内隔离“或”语句。
推荐阅读
- python - Python datetime 不与系统时间同步
- git - 如果它们相互依赖,如何提出拉取请求?
- angular - Angular 10 中的 Paypal 按钮 - 强制“通过借记卡或信用卡付款”打开一个新窗口
- sql - 计算数据是否不唯一
- javascript - 如果它落到基线,你如何改变点颜色?
- regex - 如何在 VB.net 中使用正则表达式进行捕获
- django - 对 Rail 和 Django 项目使用相同的 postgres db?
- android - 需要通过 Retrofit 将 JSON 作为对象数组发布,同时动态添加对象
- docker - GitLab CI 启动意外 docker:dind 版本
- vba - 有没有办法告诉 Word VBA 中粘贴的内容源?