如何解决 (standard_in) 1: 语法错误
how to resolve (standard_in) 1: syntax error
我正在尝试为快速节点管理器 (fnm) 创建一个更新脚本,每当发布新的主要版本(如 1.26.0)和次要版本(如 1.25.0)时,它将提示用户更新 fnm。 1)被忽略。
这是我的代码:
#!/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
$insane
仅用于测试目的(因为我已经安装了最新版本,即 1.25.0)并将在生产中删除。当版本代码相同时,一切都很好。但是,当我使用 $insane
比较版本代码时,输出是
Note: Minor versions are ignored for now.
Checking for updates...
(standard_in) 1: syntax error
Your fnm version is outdated! The currently installed version is 1.25 while the latest version is 1.25. Do you wish to update fnm (y/n):
n
Thanks for using this script.
请帮我解决 (standard_in) 1: syntax error
错误 :)
错误来自这一行:
if [[ $(bc <<< "$insane >= $latestVersion") -eq 1 ]]
$insane
是 1.0.0
,这不是有效数字,因为它有两个小数点。 bc
是一个数学计算器,它只适用于正确的数字。
当代码设置$latestVersion
和$installedVersion
时,它使用cut -d "." -f1,2
,所以它们只有一位小数点。您应该对 $insane
.
使用类似的格式
不清楚您一开始为什么要与 $insane
进行比较。如果你想知道你的版本是否是最新的,你应该比较$installedVersion
。
这似乎也是一个问题:
$(curl -fsSL https://fnm.vercel.app/install | bash)
你不应该把它放在里面 $(...)
。这将尝试将脚本的输出作为另一个命令行执行。只需将 curl
输出通过管道传输到 bash
就足以执行它。
curl -fsSL https://fnm.vercel.app/install | bash
而且你在很多地方使用了未定义的变量 ${spacing}
和 ${N}
。
我正在尝试为快速节点管理器 (fnm) 创建一个更新脚本,每当发布新的主要版本(如 1.26.0)和次要版本(如 1.25.0)时,它将提示用户更新 fnm。 1)被忽略。 这是我的代码:
#!/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
$insane
仅用于测试目的(因为我已经安装了最新版本,即 1.25.0)并将在生产中删除。当版本代码相同时,一切都很好。但是,当我使用 $insane
比较版本代码时,输出是
Note: Minor versions are ignored for now.
Checking for updates...
(standard_in) 1: syntax error
Your fnm version is outdated! The currently installed version is 1.25 while the latest version is 1.25. Do you wish to update fnm (y/n):
n
Thanks for using this script.
请帮我解决 (standard_in) 1: syntax error
错误 :)
错误来自这一行:
if [[ $(bc <<< "$insane >= $latestVersion") -eq 1 ]]
$insane
是 1.0.0
,这不是有效数字,因为它有两个小数点。 bc
是一个数学计算器,它只适用于正确的数字。
当代码设置$latestVersion
和$installedVersion
时,它使用cut -d "." -f1,2
,所以它们只有一位小数点。您应该对 $insane
.
不清楚您一开始为什么要与 $insane
进行比较。如果你想知道你的版本是否是最新的,你应该比较$installedVersion
。
这似乎也是一个问题:
$(curl -fsSL https://fnm.vercel.app/install | bash)
你不应该把它放在里面 $(...)
。这将尝试将脚本的输出作为另一个命令行执行。只需将 curl
输出通过管道传输到 bash
就足以执行它。
curl -fsSL https://fnm.vercel.app/install | bash
而且你在很多地方使用了未定义的变量 ${spacing}
和 ${N}
。