小编mol*_*ule的帖子

在我的shell程序中获取C程序的返回码

假设我有一个名为C程序Foo.c,它正在打印一些东西并返回一个名为rc我在shell程序中执行的值,如下所示:

foobar=$(Foo | tail -1)

现在,变量foobar具有程序的最后打印值Foo.但是在不打扰这个的情况下,我想rc在shell程序中获取程序的返回码.

c bash shell

14
推荐指数
3
解决办法
5039
查看次数

如何为bash变量指定多行值

我有一个变量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不适合我,因为我正在进行密集的字符串操作,并且代码格式也很重要.

bash shell

13
推荐指数
1
解决办法
2万
查看次数

当分割成多行时,如何避免回声中的空格

我有一个很长的字符串要通过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)

我找不到任何可以完美做到这一点的工作回应.

linux bash shell

7
推荐指数
1
解决办法
896
查看次数

如何使用 mongodb 验证器验证对象数组?

我一直在尝试使用 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 mongodb-query

4
推荐指数
2
解决办法
3638
查看次数

如何删除应用于我的收藏的验证规则?

我是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命令中看到它,但现在我想删除这个规则,但我无法找到在任何地方执行此操作的方法.

我该如何删除?还有什么方法可以将验证器应用于存在以及非现有集合的集合?

mongodb

3
推荐指数
1
解决办法
1641
查看次数

标签 统计

bash ×3

shell ×3

mongodb ×2

c ×1

linux ×1

mongodb-query ×1