小编inc*_*1to的帖子

扩展文件属性和bash

我在Ubuntu bash中遇到了一个有趣的行为,我无法完全理解.如果我将扩展文件属性添加到文件然后更改它 - 属性将从文件中删除.从我的观点来看,这是好的.

user@user:~/tmp$ echo "aaa" > testattr
user@user:~/tmp$ setfattr --name "user.test" --value "Tested" testattr 
user@user:~/tmp$ getfattr --name "user.test" testattr
# file: testattr
user.test="Tested"
user@user:~/tmp$ vi testattr 
< change something in file and save it > 
user@user:~/tmp$ getfattr --name "user.test" testattr
testattr: user.test: No such attribute
Run Code Online (Sandbox Code Playgroud)

但是如果我使用bash在文件中写一些东西 - 文件属性就在它的位置.任何人都可以解释这种行为吗?

user@user:~/tmp$ echo "aaa" > testattr
user@user:~/tmp$ setfattr --name "user.test" --value "Tested" testattr 
user@user:~/tmp$ getfattr --name "user.test" testattr
# file: testattr
user.test="Tested"
user@user:~/tmp$ echo "bbb" > testattr
user@user:~/tmp$ getfattr --name "user.test" …
Run Code Online (Sandbox Code Playgroud)

linux bash ubuntu attr

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

迭代通过null终止的数组

我想迭代通过null终止的结构数组.虽然循环工作正常,但当我尝试访问任何结构字段时,我得到"段错误"作为响应.我究竟做错了什么?

PS我知道可以确定数组大小并使用简单的"for"构造.我只想弄清楚问题的根源.

PSS好的,如果数组初始化错误 - 怎么做正确?

#include <stdio.h> 
#include <stdlib.h> 

typedef struct demo
{
    int a;
    int b;
    int c;
} demo;

demo * fieldDefinitions[] =
{
  { 1 , 1,  1 },
  { 2 , 2,  2 },
  { 3 , 3,  3 },
  NULL
};

int main()
{
    demo ** ptr = fieldDefinitions;
    printf( "Array: %d \n", &fieldDefinitions );

    while ( *ptr != NULL )
    {
        printf( "ptr: %d \n", ptr );
        printf( "ptr: %d \n", (**ptr).a ); // …
Run Code Online (Sandbox Code Playgroud)

c pointers

0
推荐指数
1
解决办法
2358
查看次数

标签 统计

attr ×1

bash ×1

c ×1

linux ×1

pointers ×1

ubuntu ×1