我有一個如下的 bash 腳本,它會生成伴隨的錯誤:
# cat ./a.sh
#!/bin/bash
let C=1 (2)
echo $C
#
# ./a.sh
./a.sh: line 2: syntax error near unexpected token `('
./a.sh: line 2: `let C=1 (2)'
但是,它可以從命令列按預期作業:
# let C=1 (2)
# echo $C
3
如果我將腳本中的“let”運算式更改為以下內容,它也可以作業:
C=$((1 (2)))
我的 bash 版本如下:
# /bin/bash --version
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3 : GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
作業系統是 CentOS 7.7
uj5u.com熱心網友回復:
啊,這是罪魁禍首:在互動式會話中:
$ declare -p BASH_VERSINFO
declare -ar BASH_VERSINFO='([0]="4" [1]="2" [2]="45" [3]="1" [4]="release" [5]="i386-apple-darwin19.5.0")'
$ let C=1 (2) && echo $C
3
$ shopt -u extglob
$ let C=1 (2) && echo $C
bash: syntax error near unexpected token `('
(pattern)是一個擴展的 glob 模式,當extglob它被關閉時,它顯然是非法的語法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/417452.html
標籤:
上一篇:Tokio頻道發送,但不接收
