首页 > 解决方案 > 如何将 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')"

它不会执行命令。有人可以帮我弄这个吗

标签: linuxbashshell

解决方案


这个命令会做同样的事情,试试这个 -

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 时,我做了一些修改。


推荐阅读