AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[posix](unix)

Martin Hope
peterh
Asked: 2024-04-23 02:52:28 +0800 CST

禁止 Posix 中的某些内容使用空字符串作为文件名?

  • 5

我的经验是,尝试使用空字符串文件名执行任何操作都会导致找不到文件 ( ENOENT),包括ls -ld '',touch ''或mkdir ''. 但我只能尝试 ext4。

虽然这对我来说看起来很合乎逻辑,但 Posix 中是否有什么东西会禁止这样做呢?

posix
  • 1 个回答
  • 26 Views
Martin Hope
justsome631
Asked: 2023-09-08 08:01:58 +0800 CST

为什么为 ls 以及 du 中的 --dereference-command-line 和 --dereference 选择 -H 和 -L?

  • 5

为什么分别选择was 和-Hin以及for ?-L--dereference-command-line--dereferencelsdu

我猜想-H和-L被认为不太常用,因此可以在多个实用程序中使用而不会发生冲突。如果没有好的历史原因,也许有人有好的助记符。

posix
  • 1 个回答
  • 48 Views
Martin Hope
justsome631
Asked: 2023-08-31 21:35:00 +0800 CST

为什么 XCU 是“Shell and Utilities”的缩写,而 XSH 是“System Interfaces”的缩写?

  • 5

为什么 XCU 是“Shell and Utilities”的缩写,而 XSH 是“System Interfaces”的缩写?

POSIX 分为 4 个主要卷,全文使用缩写 XBD、XSH、XCU 和 XRAT,分别代表“基本定义”、“Shell 和实用程序”、“系统接口”和“基本原理”。第一个和最后一个缩写是有道理的,但“Shell and Utilites”甚至不包含“H”,而且“System Interfaces”也不包含“C”或“U”。就其价值而言,它们应该被称为 XSU 和 XSI,而不是 XSH 和 XCU。

想法?

posix
  • 1 个回答
  • 35 Views
Martin Hope
halloleo
Asked: 2023-06-16 17:08:33 +0800 CST

在 Synology DSM 上找不到文件命令

  • 5

我在我的 NAS 上运行 Synology DSM。当我登录到 shell 时,我很惊讶该file命令不可用。

  1. Synology 从哪里获取它的最佳位置?

  2. 另外,我预计该file命令是大多数 UNIX 发行版中的标准命令。它通常是 GNU utils 的一部分吗?那么 Synology 是不是很奇怪呢?

posix
  • 1 个回答
  • 27 Views
Martin Hope
Marcin Król
Asked: 2023-06-07 00:09:10 +0800 CST

使用 utf8 字符扩展文件中的选项卡

  • 6

我用来expand将制表符扩展到空格。对于utf8文件expand不能正常工作。例如,inć\ta选项卡扩展到 6 个空格,而 ina\ta扩展到 7 个空格。

如何使其适用于utf8文件?

posix
  • 1 个回答
  • 25 Views
Martin Hope
elbarna
Asked: 2023-02-23 08:35:27 +0800 CST

有点困难:如何在 zfs/nfsv4 acl 上复制 posix acl 默认值?

  • 5

假设我想要一个目录,里面创建的所有文件和目录都具有该目录的组所有者的组权限,默认权限为770。使用 posix ACL 非常简单

#create a dir..
mkdir proof

#inherit group permission "video" in this example
chmod g+s proof/
chgrp video proof/

#with setfacl make the default group with rxw permissions
setfacl -d -m g:video:rwx proof

#other are not allowed
setfacl -d -m o:--- proof/
chmod o-x proof

#give the acl
setfacl -m g:video:rwx proof

现在我在目录证明中创建一个文件和一个目录..

mkdir try1
drwxrws---+ 2 myuser video 4,0K feb 23 01:26 try1
touch file1
-rw-rw----+ 1 myuser video    0 feb 23 01:29 file1

如您所见,我得到了我想要的,目录中的所有文件都继承了权限,并将“video”组作为组所有者。这在 Linux(ext4 上的 posix acl、btrfs 等)和 Solaris (ufs) 上是可能的。

现在的问题是..如何使用在 Solaris 上使用 nfsv4 acl 的 zfs 来做到这一点?我试过在 zfs Solaris 11 主机中制作另一个目录“证明”(当然制作了 chmod g+s)

chmod A=owner@:read_attributes/read_data/execute/list_directory/read_data/write_data/append_data/execute/add_file/add_subdirectory:fd:allow,group:video:read_attributes/read_data/execute/list_directory/read_data/write_data/append_data/execute/add_file/add_subdirectory:fd:allow,everyone@:read_attributes/read_data/execute/list_directory/read_data/write_data/append_data/execute/add_file/add_subdirectory:fd:deny proof

但结果是..

mkdir newdir
drwxr-sr-x+ 2 myuser video 2 23 feb 02.33 newdir

:|

如何获取posix acl的相同内容?谢谢

posix
  • 1 个回答
  • 17 Views
Martin Hope
Venem
Asked: 2022-07-07 08:58:58 +0800 CST

根据行内容排列文本

  • 0

是否可以插入新行以排列文件的内容?

我有:

1:1   Lorem ipsum dolor sit amet consectetur    1:1   This is sample text of varying length.
      adipiscing elit.                          1:2   This is another paragraph in this file.
1:2   Vivamus integer non suscipit taciti mus         Yet another sentence in this paragraph.
      etiam at primis tempor sagittis.          1:3   Another paragraph can be found here!

如何适当地添加空格以使数字对齐?

预期输出:

1:1   Lorem ipsum dolor sit amet consectetur          This is sample text of varying length.
      adipiscing elit.                          
1:2   Vivamus integer non suscipit taciti mus         This is another paragraph in this file.    
      etiam at primis tempor sagittis.                Yet another sentence in this paragraph.
1:3                                                   Another paragraph can be found here!

编辑:由于线条会排列,因此无需重复数字,因此可以将其删除。

POSIX 合规性是首选。

shell posix
  • 1 个回答
  • 55 Views
Martin Hope
rannday
Asked: 2022-06-17 04:57:37 +0800 CST

当前目录的 POSIX One-Liner - 试图使其通过 ShellCheck

  • 1

mklement0 中关于 POSIX 兼容脚本和获取完整路径的讨论中的单行代码。它失败了 ShellCheck。删除空间会导致它不再工作。
https://stackoverflow.com/questions/29832037/how-to-get-script-directory-in-posix-sh

dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
             ^-- SC1007: Remove space after = if trying to assign a value (for empty string, use var='' ... ).

删除CDPATH= ShellCheck 传递的结果,它似乎仍然有效,但是......

CDPATH= 前缀取代了原始命令中的 > /dev/null:$CDPATH 设置为空字符串,以确保 cd 永远不会回显任何内容。

看起来是需要的。那么,有没有办法让这个通过ShellCheck呢?还是直接忽略?

posix shellcheck
  • 1 个回答
  • 24 Views
Martin Hope
Tavian Barnes
Asked: 2022-06-01 08:50:32 +0800 CST

find -exec /no/such/file {} \; 是否符合 POSIX?退出错误?

  • 2

我是find尝试与 POSIX(以及许多流行的扩展)兼容的替代品的作者。最近我注意到我的实用程序的行为与其他实现之间存在差异find,我想知道 POSIX 是否允许我的行为,或者我是否需要更改它。

$ find . -exec /no/such/file {} \;
find: ‘/no/such/file’: No such file or directory
$ echo $?
0
$ bfs . -exec /no/such/file {} \;
bfs: error: .: -exec /no/such/file: No such file or directory.
$ echo $?
1

在这种情况下,至少 GNU、busybox 和 FreeBSD find 都具有退出状态 0。execv()我的实现将错误从ed 子级传播fork()到父级,而其他实现似乎直接从子级打印错误而不告诉父级。

我之所以问这个问题,而不是仅仅改变行为以匹配其他问题,是因为使用posix_spawn(). 的实现posix_spawn()被允许将execv()错误传播到errno父级中,例如glibc,musl两者都这样做。似乎无法判断错误是发生在 之前还是之后fork(),并且可能来自fork()(例如ENOMEM)之前的错误应该导致非零退出状态。

我已经阅读了POSIX 规范find,但这里的细节很简单。但是,我听说其他地方记录了其他可能相关的规则。例如,我听说如果一个实用程序打印到标准错误,它也必须以非零退出代码退出,这似乎暗示其他finds 不兼容。但我不确定那个措辞在哪里,或者它是否真的存在。

find posix
  • 1 个回答
  • 87 Views
Martin Hope
quasar
Asked: 2022-05-20 18:47:23 +0800 CST

POSIX shell 注释与续行

  • 5

编辑以澄清我的问题:

POSIX 说:

如果 <newline> 跟在(未加引号的)<backslash> 之后,shell 应将其解释为行继续。<backslash> 和 <newline> 应在将输入拆分为标记之前删除。

然而,dash或其他实现,首先标记化输入。结果,\<newline>不被识别而是# this is a comment \被丢弃。这种行为是否符合 POSIX?同样,POSIX 说在标记化之前应删除行继续。

下面的过程真的不符合 POSIX 吗?

  1. 阅读整个输入:"echo hello ... \<newline> ... bye"
  2. 搜索未引用\<newline>并删除它们:"echo hello ... bye"
  3. 标记化:"echo"(discard ' ')"hello"(discard ' ')(discard "# ... bye")

在带有 dash-0.5.10.2-6 sh (dash) 的 Ubuntu 上,我们得到以下信息

$ cat /var/tmp/test.sh
echo hello # this is a comment \
echo bye

$ sh /var/tmp/test.sh
hello
bye

这是因为 # 之后的所有内容都被视为注释,并且 \ 之前的所有内容都被丢弃,因此 \<newline> 的行继续不起作用。

但是,POSIX“转义字符(反斜杠)”部分指出

<backslash> 和 <newline> 应在将输入拆分为标记之前删除。

并且由于# 的注释处理是在标记化中完成的,

echo hello # this is a comment \
echo bye

应该相当于

echo hello # this is a comment echo bye

这是否意味着 sh 不符合 POSIX 标准?或者在这种情况下,评论优先于行延续是否有一些理由?

shell posix
  • 3 个回答
  • 501 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve