ฉันได้รับข้อผิดพลาดทางไวยากรณ์ของข้อผิดพลาดใกล้ else
คุณสามารถใช้ได้ http://www.shellcheck.net/ เพื่อตรวจสอบไวยากรณ์ของคุณ:
$ shellcheck myscript
Line 1:
if [ -z $loc ] then
^-- SC1010: Use semicolon or linefeed before 'then' (or quote to make it literal).
Line 2:
if [uname -a| grep 64 >/dev/null] then
^-- SC1009: The mentioned parser error was in this if expression.
^-- SC1073: Couldn't parse this test expression.
^-- SC1035: You need a space after the [ and before the ].
^-- SC1009: Use 'if cmd; then ..' to check exit code, or 'if [[ $(cmd) == .. ]]' to check output.
^-- SC1035: You are missing a required space here.
^-- SC1072: Fix any mentioned problems and try again.
$
แก้ไขข้อผิดพลาดที่ชัดเจน (หายไป ;
s และช่องว่างให้:
if [ -z $loc ]; then
if [ uname -a | grep 64 >/dev/null ] then
sdir=$KALDI_ROOT/tools/srilm/bin/i686-m64
else
sdir=$KALDI_ROOT/tools/srilm/bin/i686
fi
if [ -f $sdir/ngram-count ]; then
echo "Using SRILM language modelling tool from $sdir"
export PATH=$PATH:$sdir
else
echo "SRILM toolkit is probably not installed.
Instructions: tools/install_srilm.sh"
exit 1
fi
fi
และ:
$ shellcheck myscript
Line 2:
if [ uname -a | grep 64 >/dev/null ]; then
^-- SC1009: The mentioned parser error was in this if expression.
^-- SC1073: Couldn't parse this test expression.
^-- SC1009: Use 'if cmd; then ..' to check exit code, or 'if [[ $(cmd) == .. ]]' to check output.
^-- SC1072: Fix any mentioned problems and try again.
$
คุณสามารถแก้ไขข้อผิดพลาดที่เหลือได้ด้วยตนเอง
ShellCheck - เครื่องมือวิเคราะห์สคริปต์เชลล์แบบสแตติก
ShellCheck เป็นเครื่องมือ GPLv3 ที่ให้คำเตือนและคำแนะนำสำหรับ
สคริปต์เชลล์ bash / sh:
สกรีนช็อตของเทอร์มินัลแสดงบรรทัดสคริปต์เชลล์ที่มีปัญหา
ไฮไลต์
เป้าหมายของ ShellCheck คือ
เพื่อชี้ให้เห็นและชี้แจงปัญหาทางไวยากรณ์ของผู้เริ่มต้นทั่วไปที่ทำให้เชลล์ให้ข้อความแสดงข้อผิดพลาดแบบเข้ารหัส
เพื่อชี้ให้เห็นและชี้แจงปัญหาความหมายระดับกลางทั่วไปที่ทำให้เชลล์ทำงานผิดปกติและ
เคาน์เตอร์สังหรณ์ใจ
เพื่อชี้ให้เห็น caveats ที่ละเอียดอ่อนมุมตัวพิมพ์เล็กและข้อผิดพลาดที่อาจทำให้สคริปต์การทำงานของผู้ใช้ขั้นสูงล้มเหลวในอนาคต
พฤติการณ์
แหล่ง ShellCheck