Bash 如何解决(标准_in)1:语法错误

Bash 如何解决(标准_in)1:语法错误,bash,syntax-error,Bash,Syntax Error,我正在尝试为Fast Node Manager(fnm)创建一个更新脚本,每当发布新的主要版本(如1.26.0)而忽略次要版本(如1.25.1)时,该脚本将提示用户更新fnm。 这是我的密码: #!/bin/bash # get the latest version latestVersion=$(curl -s https://api.github.com/repos/Schniz/fnm/releases/latest | grep tag_name | cut -d ":&qu

我正在尝试为Fast Node Manager(fnm)创建一个更新脚本,每当发布新的主要版本(如1.26.0)而忽略次要版本(如1.25.1)时,该脚本将提示用户更新fnm。 这是我的密码:

#!/bin/bash

# get the latest version
latestVersion=$(curl -s https://api.github.com/repos/Schniz/fnm/releases/latest | grep tag_name | cut -d ":" -f2 | cut -d "," -f1 | cut -d "v" -f2 | cut -d "." -f1,2)

# get currently installed version
installedVersion=$(fnm -V | cut -d " " -f2 | cut -d "." -f1,2)
insane="1.0.0"
# statement to be printed if fnm is already up to date
upToDateMessage="${spacing} Your fnm version is up to date."

# statement to be printed if fnm needs to be updated
outdatedMessage="${spacing} Your fnm version is outdated! The currently installed version is "$installedVersion" while the latest version is "$latestVersion". Do you wish to update fnm (y/n): "

echo -e "${spacing} Checking for updates..."
echo -e "${N}"

# the main if-else statement
if [[ $(bc <<< "$insane >= $latestVersion") -eq 1 ]]; then
   echo -e $upToDateMessage
else
   echo -e $outdatedMessage
   read user_input
     if [ $user_input == y ]; then
       echo -e "${spacing} Updating fnm..."
       $(curl -fsSL https://fnm.vercel.app/install | bash)
     elif [ $user_input == n ]; then
       echo -e "${spacing} Thanks for using this script."
       exit
     else
       echo -e "${spacing} Invalid input! Please answer in y or n."
       exit
   fi
fi 

请帮助我解决
(标准)1:语法错误
错误:)

错误来自以下行:

if [[ $(bc <<< "$insane >= $latestVersion") -eq 1 ]]
你不应该把它放在
$(…)
里面。它将尝试以另一个命令行的形式执行脚本的输出。只需将
curl
输出管道化到
bash
就足以执行它

curl -fsSL https://fnm.vercel.app/install | bash

在许多地方使用未定义的变量
${spating}
${N}

错误来自这一行:

if [[ $(bc <<< "$insane >= $latestVersion") -eq 1 ]]
你不应该把它放在
$(…)
里面。它将尝试以另一个命令行的形式执行脚本的输出。只需将
curl
输出管道化到
bash
就足以执行它

curl -fsSL https://fnm.vercel.app/install | bash

您可以在许多地方使用未定义的变量
${spating}
${N}

除了设置
最新版本
疯狂
bc
命令的三行之外,删除所有内容如何?请参阅。除了设置
最新版本
疯狂
、和
bc
命令的三行之外,删除所有内容如何?看,谢谢。我将
$insane
的值从
1.0.0
更改为
1.0
,它成功了:)谢谢。我仍然不明白这种比较如何意味着安装的版本是最新的。
$insane
只是用于测试,一旦代码正常工作,它将被删除。我有最新版本的fnm,因此,我的if逻辑将始终返回true(除非我安装了过时的版本),但我还想测试当if逻辑返回false时会发生什么。所以,我用了
$indane
。因此,在最后的代码中没有使用
$insane
。简单:)顺便说一句,原谅我,我回答得太晚了:谢谢。我将
$insane
的值从
1.0.0
更改为
1.0
,它成功了:)谢谢。我仍然不明白这种比较如何意味着安装的版本是最新的。
$insane
只是用于测试,一旦代码正常工作,它将被删除。我有最新版本的fnm,因此,我的if逻辑将始终返回true(除非我安装了过时的版本),但我还想测试当if逻辑返回false时会发生什么。所以,我用了
$indane
。因此,在最后的代码中没有使用
$insane
。简单:)顺便说一句,原谅我,我回答得太晚了:b