我剛開始學習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
當我想看到在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兼容的結果解決了'找不到的命令'。更可以在這裏找到,'\r': command not found - .bashrc/.bash_profile
你用什麼程序創建'package.sh'?記事本?所有'package.sh:line foo:$'\ r':command not found'錯誤的原因是因爲Window的新換行符是'\ r \ n',而Linux新換行符只是'\ r' N'。所以'bash'解析'\ n'轉義就好,但不知道如何處理'\ r'轉義。 –
@JonnyHenly:幾分鐘前解決了。剛剛看到您的評論。無論如何,謝謝 – PraveenMax