假设我有一个名为C程序Foo.c,它正在打印一些东西并返回一个名为rc我在shell程序中执行的值,如下所示:
foobar=$(Foo | tail -1)
现在,变量foobar具有程序的最后打印值Foo.但是在不打扰这个的情况下,我想rc在shell程序中获取程序的返回码.
我有一个变量FOO与我需要分配一个多行的值.像这样的东西,
FOO="This is line 1
This is line 2
This is line 3"
Run Code Online (Sandbox Code Playgroud)
所以当我打印FOO它的值时应该给出以下输出.
echo $FOO
output:
This is line 1
This is line 2
This is line 3
Run Code Online (Sandbox Code Playgroud)
此外,行数将动态决定,因为我将使用循环初始化它.
主要使用的另一个问题中显示的答案read -d不适合我,因为我正在进行密集的字符串操作,并且代码格式也很重要.
我有一个很长的字符串要通过echo命令打印.通过这样做,我希望它完美缩进.我正在尝试这个,它完美地工作
echo "This is a very long string. An"\
"d it is printed in one line"
Output:
This is a very long string. And it is printed in one line
Run Code Online (Sandbox Code Playgroud)
但是当我尝试缩进它时,因为echo语句也是缩进的.它增加了额外的空间.
echo "This is a very long string. An"\
"d it is printed in one line"
Output:
This is a very long string. An d it is printed in one line
Run Code Online (Sandbox Code Playgroud)
我找不到任何可以完美做到这一点的工作回应.
我一直在尝试使用 MongoDB 提供的验证器来验证我的数据,但我遇到了一个问题。这是我正在插入的一个简单的用户文档。
{
"name" : "foo",
"surname" : "bar",
"books" : [
{
"name" : "ABC",
"no" : 19
},
{
"name" : "DEF",
"no" : 64
},
{
"name" : "GHI",
"no" : 245
}
]
}
Run Code Online (Sandbox Code Playgroud)
现在,这是已应用于用户集合的验证器。但这现在适用于我与文档一起插入的书籍数组。我想检查对象内的元素,这些元素是书籍数组的成员。对象的架构不会改变。
db.runCommand({
collMod: "users",
validator: {
$or : [
{ "name" : { $type : "string" }},
{ "surname" : { $type : "string" }},
{ "books.name" : { $type : "string" }},
{ "books.no" : { $type : "number" }} …Run Code Online (Sandbox Code Playgroud) 我是mongodb的新手,我正在尝试数据库本身提供的文档验证器.这是我写的命令
db.runCommand({
collMod: "admin",
validator: {
$or : [
{ isActive : { $type : "bool" }},
],
$and: [
{ name : { $type : "string" }},
{ mobileNumber : { $type : "int" }},
]
},
validationAction: "error",
validationLevel: "strict"
});
Run Code Online (Sandbox Code Playgroud)
所以它执行得很完美,我可以在getCollectionInfo命令中看到它,但现在我想删除这个规则,但我无法找到在任何地方执行此操作的方法.
我该如何删除?还有什么方法可以将验证器应用于存在以及非现有集合的集合?