linux - 如何将 bash 命令转换为在 shell 上执行
问题描述
嗨,我正在尝试在 shell 脚本中运行 bash 命令,但由于我对 Linux/Unix 的了解非常少,因此无法完全弄清楚如何操作。
这是命令:
bash <(curl -s https://raw.githubusercontent.com/TitouanVanBelle/XCTestHTMLReport/master/install.sh) '1.0.0'
我可以在没有这样的版本的情况下在 shell 中执行命令:
/bin/bash -c "$(curl -s https://raw.githubusercontent.com/TitouanVanBelle/XCTestHTMLReport/master/install.sh)"
但如果我尝试通过这样的版本:
/bin/bash -c "$(curl -s https://raw.githubusercontent.com/TitouanVanBelle/XCTestHTMLReport/master/install.sh) '1.0.0'"
或者
/bin/bash -c "$(curl -s https://raw.githubusercontent.com/TitouanVanBelle/XCTestHTMLReport/master/install.sh '1.0.0')"
它不会执行命令。有人可以帮我弄这个吗
解决方案
这个命令会做同样的事情,试试这个 -
curl -s https://raw.githubusercontent.com/TitouanVanBelle/XCTestHTMLReport/master/install.sh | bash -s '1.0.0'
curl 从在线下载此脚本,下载完成后,该文件将由 bash 运行,而 bash 会将参数“1.0.0”传递给它以下载此特定版本的 XCTestHTMLReport(默认为 1.6.1 版)。
或者你可以简单地在你的计算机上创建一个脚本文件,然后运行它来做同样的事情。
#!/bin/bash
set -e
VERSION=$1
if [ -z $VERSION ] ; then
VERSION="1.0.0"
fi
OUT_ZIP="xchtmlreport.zip"
printf "Downloading xchtmlreport $VERSION\n"
CURL=$(curl -L -s -w "%{http_code}" -o $OUT_ZIP https://github.com/TitouanVanBelle/XCTestHTMLReport/releases/download/$VERSION/xchtmlreport-$VERSION.zip)
if [ ! -f $OUT_PATH ]; then
printf '\e[1;31m%-6s\e[m' "Failed to download XCTestHTMLReport. Make sure the version you're trying to download exists."
printf '\n'
exit 1
fi
unzip $OUT_ZIP
chmod 755 xchtmlreport
mv xchtmlreport /usr/local/bin/
rm $OUT_ZIP
printf '\e[1;32m%-6s\e[m' "Successully installed XCTestHTMLReport. Execute xchtmlreport -h for help."
printf '\n'
exit 0
当我将默认版本更改为 1.0.0 时,我做了一些修改。
推荐阅读
- excel - 提取两个特定字符或数字之间的单词
- ruby - 如果消息为空,则 Logstash 删除整行
- angular - 订阅者内部的订阅者在离子项目中无法正常工作
- java - 由于 GSON 库中的 CLOB 数据类型导致的异常
- javascript - 我有一个问题 javascript 切换索引
- react-native - 在 IOS 13 中从服务器获取消息时未设置徽章
- tensorflow-model-garden - 如何使用模型/官方/视觉/检测训练自定义模型进行对象检测?
- python - ML Pipeline OneHotEncoder 不适合
- css - 在 Bootstrap 中重叠两个 div
- javascript - 在 React 中调用 set state 时如何从数组中获取更新的 ID