"BUILD_TARGET=${1:-none}" 这一行在 shell 脚本中是什么意思?
What does this line "BUILD_TARGET=${1:-none}" means in shell scripting?
我刚开始学习 shell 脚本,所以请原谅我是否太基础而不能在这里问。我想要 运行 这个 sh 脚本
(https://github.com/daid/Cura/blob/SteamEngine/package.sh)。
但我无法理解这一行( BUILD_TARGET=${1:-none} )的作用?
摘录如下:
#!/usr/bin/env bash
set -e
set -u
# This script is to package the Cura package for Windows/Linux and Mac OS X
# This script should run under Linux and Mac OS X, as well as Windows with Cygwin.
#############################
# CONFIGURATION
#############################
##Select the build target
BUILD_TARGET=${1:-none}
#BUILD_TARGET=win32
#BUILD_TARGET=darwin
#BUILD_TARGET=debian_i386
#BUILD_TARGET=debian_amd64
#BUILD_TARGET=debian_armhf
#BUILD_TARGET=freebsd
##Do we need to create the final archive
ARCHIVE_FOR_DISTRIBUTION=1
##Which version name are we appending to the final archive
export BUILD_NAME=15.04.6
TARGET_DIR=Cura-${BUILD_NAME}-${BUILD_TARGET}
##Which versions of external programs to use
WIN_PORTABLE_PY_VERSION=2.7.2.1
当我试图通过 运行ning 在 Cygwin 中查看其工作原理时,它抛出以下错误,
$ bash package.sh
package.sh: line 2: $'\r': command not found
: invalid option 3: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
: invalid option 4: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
package.sh: line 5: $'\r': command not found
package.sh: line 8: $'\r': command not found
package.sh: line 12: $'\r': command not found
package.sh: line 21: $'\r': command not found
package.sh: line 27: $'\r': command not found
package.sh: line 30: $'\r': command not found
package.sh: line 48: syntax error near unexpected token `$'{\r''
'ackage.sh: line 48: `{
我在 Cygwin 中缺少什么?
更新 1:我通过将行结尾转换为 unix 兼容的结尾来解决 'command not found'。更多可以在这里找到,'\r': command not found - .bashrc / .bash_profile
</code> 是第一个命令行参数 <br></p>
<p><code>${1:-none}
表示如果第一个命令行参数未设置或为空,则替换为“none”。
否则,第一个命令行参数的值被替换。
有关详细信息,请查看 [ shell parameter expansion ]。
我刚开始学习 shell 脚本,所以请原谅我是否太基础而不能在这里问。我想要 运行 这个 sh 脚本 (https://github.com/daid/Cura/blob/SteamEngine/package.sh)。 但我无法理解这一行( BUILD_TARGET=${1:-none} )的作用?
摘录如下:
#!/usr/bin/env bash
set -e
set -u
# This script is to package the Cura package for Windows/Linux and Mac OS X
# This script should run under Linux and Mac OS X, as well as Windows with Cygwin.
#############################
# CONFIGURATION
#############################
##Select the build target
BUILD_TARGET=${1:-none}
#BUILD_TARGET=win32
#BUILD_TARGET=darwin
#BUILD_TARGET=debian_i386
#BUILD_TARGET=debian_amd64
#BUILD_TARGET=debian_armhf
#BUILD_TARGET=freebsd
##Do we need to create the final archive
ARCHIVE_FOR_DISTRIBUTION=1
##Which version name are we appending to the final archive
export BUILD_NAME=15.04.6
TARGET_DIR=Cura-${BUILD_NAME}-${BUILD_TARGET}
##Which versions of external programs to use
WIN_PORTABLE_PY_VERSION=2.7.2.1
当我试图通过 运行ning 在 Cygwin 中查看其工作原理时,它抛出以下错误,
$ bash package.sh
package.sh: line 2: $'\r': command not found
: invalid option 3: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
: invalid option 4: set: -
set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
package.sh: line 5: $'\r': command not found
package.sh: line 8: $'\r': command not found
package.sh: line 12: $'\r': command not found
package.sh: line 21: $'\r': command not found
package.sh: line 27: $'\r': command not found
package.sh: line 30: $'\r': command not found
package.sh: line 48: syntax error near unexpected token `$'{\r''
'ackage.sh: line 48: `{
我在 Cygwin 中缺少什么?
更新 1:我通过将行结尾转换为 unix 兼容的结尾来解决 'command not found'。更多可以在这里找到,'\r': command not found - .bashrc / .bash_profile
</code> 是第一个命令行参数 <br></p>
<p><code>${1:-none}
表示如果第一个命令行参数未设置或为空,则替换为“none”。
否则,第一个命令行参数的值被替换。
有关详细信息,请查看 [ shell parameter expansion ]。