我想在 shell 函数内创建一个简单的 json 文件。这是我的代码
gen_manifest () {
FILENAME="abcd"
cat > manifest.json << EOF
{
"general": {
"name": "fs",
"version": "1.0.0"
},
"install": {
"type": "rootFs",
"class": {
"category": "partition",
"image": "./${FILENAME}"
}
}
}
EOF
}
错误
Line 3:
cat > manifest.json << EOF
^-- SC1009 (info): The mentioned syntax error was in this simple command.
^-- SC1073 (error): Couldn't parse this here document. Fix to allow more checks.
Line 17:
EOF
^-- SC1039 (error): Remove indentation before end token (or use <<- and indent with tabs).
Line 18:
}
^-- SC1072 (error): Here document was not correctly terminated. Fix any mentioned problems and try again.
您可以在 shell 文档中使用 TAB 字符作为缩进;尽管您需要使用
<<-
来禁用它:
cat <<- EOF
hello
EOF
当我使用选项卡时,输出是:
hello