跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

unescape_fstab.sh

46 行 · 1.6 KB历史下载
1#!/bin/bash
2
3# SPDX-FileCopyrightText: Copyright The Lima Authors
4# SPDX-License-Identifier: Apache-2.0
5
6# Read a string on stdin and write it to stdout with the octal escapes used in
7# /etc/fstab and /proc/mounts decoded to their literal characters:
8# "\040" -> space, "\011" -> tab, "\012" -> newline, "\134" -> backslash,
9# "\043" -> "#".
10#
11# This decodes the full set of escapes the kernel emits in /proc/mounts and that
12# mount(8) reads from /etc/fstab -- a superset of what util/escape_fstab.sh
13# produces (only \040, \011 and \134). It round-trips that script's output
14# (unescape(escape(x)) == x) but is not its exact inverse.
15# https://github.com/torvalds/linux/blob/v6.6/fs/proc_namespace.c#L89
16
17set -eu
18
19: "${SELFTEST:=}"
20if [ -n "${SELFTEST}" ]; then
21 unset SELFTEST
22 tab=$(printf '\t')
23 check() {
24 local desc=$1 input=$2 want=$3 got
25 got=$(printf '%s\n' "${input}" | "$0")
26 if [ "${got}" = "${want}" ]; then
27 echo "ok: ${desc}"
28 else
29 echo "FAIL: ${desc}" >&2
30 printf ' want: %q\n got: %q\n' "${want}" "${got}" >&2
31 return 1
32 fi
33 }
34 echo >&2 "=== Running tests ==="
35 check "spaces are decoded" '/tmp/dir\040with\040spaces' "/tmp/dir with spaces"
36 check "tab is decoded" '/a\011b' "/a${tab}b"
37 check "newline is decoded" 'a\012b' "$(printf 'a\nb')"
38 check "backslash is decoded" '/a\134b' '/a\b'
39 check "hash is decoded" '/a\043b' "/a#b"
40 check "a string without escapes is unchanged" "/mnt/nospace" "/mnt/nospace"
41 check "mixed escapes are decoded" '/a\040b\134c' '/a b\c'
42 echo >&2 "=== All tests passed ==="
43 exit 0
44fi
45
46sed -e 's/\\040/ /g; s/\\011/\t/g; s/\\012/\n/g; s/\\134/\\/g; s/\\043/#/g'