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
    • 最新
    • 标签
主页 / user-64403

林果皞's questions

Martin Hope
林果皞
Asked: 2019-06-22 14:02:01 +0800 CST

如何修复 konsole `\033[0m` 从滚动的第二页开始不起作用?

  • 2

我注意到konsole在下一页滚动时重置颜色有问题,如下图所示,使用命令运行for i in {1..100}; do echo "$i"; echo -en '\033[1;42m AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA \033[0m'; echo -e 'next text'; done;:

在此处输入图像描述

在此处输入图像描述

如您所见,\033[0m get ignore 从第 11 行开始,即当前窗口视图的下一页。

gnome-terminal没有这样的问题。但我是konsole用户,正在寻找解决方案。

[更新]

我在https://bugs.kde.org/show_bug.cgi?id=409016报告了错误

colors konsole
  • 2 个回答
  • 1127 Views
Martin Hope
林果皞
Asked: 2019-03-08 12:54:52 +0800 CST

tftp - 错误代码 1:找不到文件

  • 0

我需要正确的 tftp 语法来获取和放置文件。我的最终目标是使用busybox tftp(这应该是第二个问题),但即使尝试使用本地Ubuntu tftp客户端进行测试也失败了。

正如您在下面看到的,ftp没有问题,只有tftp问题。这是回送 ip,所以不应该与 iptables 相关(同样,ftp没问题)。为了防止潜在的长路径问题,我只使用主目录进行测试。

xb@dnxb:/tmp$ grep anon_root /etc/vsftpd.conf
anon_root=/home/xiaobai/
xb@dnxb:/tmp$ cat /home/xiaobai/haha
7
xb@dnxb:/tmp$ ftp 127.0.0.1
Connected to 127.0.0.1.
220 (vsFTPd 3.0.3)
Name (127.0.0.1:xiaobai): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> get haha
local: haha remote: haha
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for haha (2 bytes).
226 Transfer complete.
2 bytes received in 0.00 secs (6.5541 kB/s)
ftp> 221 Goodbye.
xb@dnxb:/tmp$ tftp 127.0.0.1
tftp> get haha
Error code 1: File not found
tftp> get /home/xiaobai/haha
Error code 1: File not found
tftp> get /home/xiaobai/haha output
Error code 1: File not found
tftp> put /home/xiaobai/haha        
Error code 1: File not found
tftp> put haha
Error code 1: File not found
tftp> xb@dnxb:/tmp$ dpkg-query -W -f='${Description}\n\n${Homepage}\nMaintainer: ${Maintainer}\n\n' tftp
Trivial file transfer protocol client
 Tftp is the user interface to the Internet TFTP (Trivial File Transfer
 Protocol), which allows users to transfer files to and from a remote machine.
 The remote host may be specified on the command line, in which case tftp uses
 host as the default host for future transfers.

http://www.hcs.harvard.edu/~dholland/computers/netkit.html
Maintainer: Ubuntu Developers <[email protected]>

xb@dnxb:/tmp$

然后我按照这个答案:

xb@dnxb:/tmp$ tftp -v 127.0.0.1 -c get haha
usage: tftp host-name [port]
tftp> xb@dnxb:/tmp$ 
xb@dnxb:/tmp$ tftp -v 127.0.0.1 -c get /home/xiaobai/haha
usage: tftp host-name [port]
tftp> xb@dnxb:/tmp$ 
xb@dnxb:/tmp$ tftp -v 127.0.0.1 -c put haha
usage: tftp host-name [port]
tftp> xb@dnxb:/tmp$ tftp -v 127.0.0.1 -c put /home/xiaobai/haha
usage: tftp host-name [port]
tftp> ^F
?Invalid command
tftp> xb@dnxb:/tmp$ 
xb@dnxb:/tmp$ 

还有这个答案(评论或不评论似乎没有效果,我service vsftpd restart在编辑后做了):

xb@dnxb:/tmp$ grep server_args /etc/xinetd.conf 
# server_args = -c -s /tftpboot
xb@dnxb:/tmp$ 

如果有人可以回答有关具有不同选项的busybox tftp,那就更好了:

# busybox tftp                                    
BusyBox v1.22.1 bionic (2017-11-04 12:54 +0800) multi-call binary.

Usage: tftp [OPTIONS] HOST [PORT]

Transfer a file from/to tftp server

        -l FILE Local FILE
        -r FILE Remote FILE
        -g      Get file
        -p      Put file
busybox vsftpd
  • 1 个回答
  • 10372 Views
Martin Hope
林果皞
Asked: 2019-02-15 07:20:52 +0800 CST

如何在不依赖 fps 的情况下提取“存储的帧”?

  • 1

我注意到如果我用这个命令提取帧:

ffmpeg -i sample_nosound.mp4 $filename%03d.jpg

默认情况下,它将提取取决于 fps。ffmpeg -i sample_nosound.mp4显示此视频有 6 fps,因此它提取了 1630 个 jpg 帧文件,其中 1630/6 = 271.6 秒相当于 4:32 的总视频时长。

但是 1630 jpg 帧的总大小为 13 MB:

$ du -h extracted_jpg_folder
13M      extracted_jpg_folder

,而 mp4 的文件大小为 1.8 MB,远低于总帧大小:

$ ls -la sample_nosound.mp4
-rw-rw-r-- 1 xiaobai xiaobai 1814889 Feb  13 15:42 'sample_nosound.mp4'

这意味着 ffmpeg 通过引用具有重复帧的 fps 信息来提取帧。

因此我的问题是,如何在不依赖 fps 的情况下通过“存储帧”使 ffmpeg 提取帧?

我希望我可以获得与 mp4 文件大小几乎相等的总帧大小。

我不希望完全匹配文件大小,因为 mp4 可以包含一些元数据。

输出ffprobe -i sample_nosound.mp4:

ffprobe version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2007-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  WARNING: library configuration mismatch
  avcodec     configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared --enable-version3 --disable-doc --disable-programs --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libtesseract --enable-libvo_amrwbenc
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'sample_nosound.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.83.100
  Duration: 00:04:32.00, start: 0.000000, bitrate: 53 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt709/bt709), 640x330 [SAR 1:1 DAR 64:33], 53 kb/s, 6 fps, 6 tbr, 12288 tbn, 12 tbc (default)
    Metadata:
      handler_name    : VideoHandler
video ffmpeg
  • 1 个回答
  • 592 Views
Martin Hope
林果皞
Asked: 2018-04-28 07:52:15 +0800 CST

X11 语言环境文件中 47 个空行的目的是什么?

  • 2

我注意到语言环境文件顶部有 47 个空白行:

xb@dnxb:/usr/share/X11/locale$ hexdump -Cv locale.alias | head
00000000  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
00000010  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
00000020  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 23  |...............#|
00000030  0a 23 09 54 68 69 73 20  66 69 6c 65 20 63 6f 6e  |.#.This file con|
00000040  74 61 69 6e 73 20 61 6c  69 61 73 20 6e 61 6d 65  |tains alias name|
00000050  20 6f 66 20 6c 6f 63 61  6c 65 2e 0a 23 09 45 61  | of locale..#.Ea|
00000060  63 68 20 61 6c 69 61 73  20 6e 61 6d 65 20 69 73  |ch alias name is|
00000070  20 64 65 73 63 72 69 62  65 64 20 77 69 74 68 69  | described withi|
00000080  6e 20 6f 6e 65 20 6c 69  6e 65 2e 0a 23 09 54 68  |n one line..#.Th|
00000090  65 20 66 69 72 73 74 20  77 6f 72 64 20 69 73 20  |e first word is |
xb@dnxb:/usr/share/X11/locale$ hexdump -Cv locale.dir | head
00000000  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
00000010  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
00000020  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 23  |...............#|
00000030  0a 23 09 54 68 69 73 20  66 69 6c 65 20 63 6f 6e  |.#.This file con|
00000040  74 61 69 6e 73 20 6c 6f  63 61 6c 65 20 64 61 74  |tains locale dat|
00000050  61 62 61 73 65 20 66 69  6c 65 20 6e 61 6d 65 73  |abase file names|
00000060  0a 23 09 54 68 65 20 66  69 72 73 74 20 77 6f 72  |.#.The first wor|
00000070  64 20 69 73 20 74 68 65  20 6c 6f 63 61 6c 65 20  |d is the locale |
00000080  64 61 74 61 62 61 73 65  20 66 69 6c 65 20 6e 61  |database file na|
00000090  6d 65 20 61 6e 64 0a 23  09 74 68 65 20 73 65 63  |me and.#.the sec|
xb@dnxb:/usr/share/X11/locale$ hexdump -Cv compose.dir | head                                   
00000000  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
00000010  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
00000020  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 23  |...............#|
00000030  0a 23 09 54 68 69 73 20  66 69 6c 65 20 63 6f 6e  |.#.This file con|
00000040  74 61 69 6e 73 20 63 6f  6d 70 6f 73 65 20 74 61  |tains compose ta|
00000050  62 6c 65 20 66 69 6c 65  20 6e 61 6d 65 73 2e 0a  |ble file names..|
00000060  23 09 54 68 65 20 66 69  72 73 74 20 77 6f 72 64  |#.The first word|
00000070  20 69 73 20 74 68 65 20  63 6f 6d 70 6f 73 65 20  | is the compose |
00000080  74 61 62 6c 65 20 66 69  6c 65 20 6e 61 6d 65 0a  |table file name.|
00000090  23 09 61 6e 64 20 74 68  65 20 73 65 63 6f 6e 64  |#.and the second|
xb@dnxb:/usr/share/X11/locale$ hexdump -Cv C/XLC_LOCALE | head
00000000  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
00000010  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 0a  |................|
00000020  0a 0a 0a 0a 0a 0a 0a 0a  0a 0a 0a 0a 0a 0a 0a 23  |...............#|
00000030  20 20 58 4c 6f 63 61 6c  65 20 44 61 74 61 62 61  |  XLocale Databa|
00000040  73 65 20 53 61 6d 70 6c  65 20 66 6f 72 20 43 2e  |se Sample for C.|
00000050  0a 23 20 0a 0a 23 20 0a  23 20 09 58 4c 43 5f 46  |.# ..# .# .XLC_F|
00000060  4f 4e 54 53 45 54 20 63  61 74 65 67 6f 72 79 0a  |ONTSET category.|
00000070  23 20 0a 58 4c 43 5f 46  4f 4e 54 53 45 54 0a 23  |# .XLC_FONTSET.#|
00000080  20 09 66 73 30 20 63 6c  61 73 73 20 28 37 20 62  | .fs0 class (7 b|
00000090  69 74 20 41 53 43 49 49  29 0a 66 73 30 09 7b 0a  |it ASCII).fs0.{.|
xb@dnxb:/usr/share/X11/locale$ 

vi如果我只看到文件并看到空白页,我可能不会向下滚动,如果我这样做了,我只会注意到这cat一点。我检查了这个规范,但似乎没有提到任何关于 47 个空白行的内容。语言环境文件开头的这 47 个空白行的目的是什么?

x11 locale
  • 1 个回答
  • 142 Views
Martin Hope
林果皞
Asked: 2018-03-10 04:20:48 +0800 CST

为什么没有这种非交互版本的 bashrc?

  • 4

据我了解,守护进程是一个后台进程,但守护进程需要唯一的配置文件来设置环境变量。

例如 Hadoop 守护进程需要hadoop-env.sh来设置环境变量JAVA_HOME,你不能简单地从~/.bashrc.

原因是因为 daemon 作为后台进程意味着它是非交互式的,而 ~/.bashrc 意味着只能从交互式会话中使用,以防止alias cp='cp -i'case。

最新~/.bashrc的文件顶部有安全防护,不允许非交互式调用者,即没有-i选项将提前返回:

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

这让我想知道为什么 bashrc 不将配置文件分成 3 组,例如:

  • ~/.bashrc_interactive

  • ~/.bashrc_non_interactive

  • ~/.bashrc_global #(交互式和非交互式)

因此用户可以简单地设置or ,而无需在每个守护程序文件中一遍又一遍地添加此环境变量JAVA_HOME。~/.bashrc_non_interactive~/.bashrc_global

为什么 bashrc 不以这种方式或任何其他方式支持非交互式,是否有任何理由或限制?还是我误解了一些概念?

environment-variables bashrc
  • 2 个回答
  • 2773 Views
Martin Hope
林果皞
Asked: 2018-02-28 06:24:27 +0800 CST

怎么可能分配了 8 个块但文件大小为 0?

  • 9

有人在其他网站上问我这个问题,即一个名为“abc.dat”的文件的文件大小为0,但有8个块,这是我要求他给我的输出(部分文本已从中文翻译成英文):

$ cp abc.dat abc2.dat; ls -ls abc2.dat #try to copy, it still 8 blocks but 0 byte
8 -rw-rw-r--  1 rokeabbey rokeabbey      0 Feb  27 19:39 abc2.dat 

8 -rw-rw-r-- 1 rokeabbey rokeabbey 0 Sep 18 19:11 abc.dat #sorry,这可能是他添加的额外错误输出

$ stat abc.dat
  File: 'abc.dat'
  Size: 0           Blocks: 16          IO Block: 4096   regular empty file
Device: 32h/50d      Inode: 3715853    Links: 1
Access: (0664/-rw-rw-r--)  Uid:( 1000/rokeabbey)   Gid:( 1000/rokeabbey)
Access: 2018-02-26 21:13:57.640639992 +0800
Modify: 2017-09-18 19:11:42.221533011 +0800
Change: 2017-09-18 19:11:42.221533011 +0800
 Birth: -

$ touch abc3.dat ; ls -sl | grep abc #try to create new empty file, it still 8 blocks by default
8 -rw-rw-r--  1 rokeabbey rokeabbey      0 Feb  27 19:39 abc2.dat
8 -rw-rw-r--  1 rokeabbey rokeabbey      0 Feb  27 19:40 abc3.dat
8 -rw-rw-r--  1 rokeabbey rokeabbey      0 Sep  18 19:11 abc.dat

我已经了解了一些关于稀疏文件、文件元数据、符号链接情况的知识,但是这些情况都不会导致 0 字节文件大小和 8 个块。是否有任何文件系统设置,例如任何文件的最小块大小?

他告诉我他的系统是 Ubuntu 16.04 和 ext4。

[更新]

$ df -Th /home/rokeabbey
/home/rokeabbey/.Private ecryptfs  138G   39G   92G   30% /home/rokeabbey

[更新]我可以用 ecryptfs 复制

xb@dnxb:/tmp/test$ sudo mkdir /opt/data
xb@dnxb:/tmp/test$ sudo apt-get install ecryptfs-utils
...
xb@dnxb:/tmp/test$ sudo mount -t ecryptfs /opt/data /opt/data
Passphrase: 
...
Selection [aes]: 1
...
Selection [16]: 1
Enable plaintext passthrough (y/n) [n]: y
Enable filename encryption (y/n) [n]: y
...
Would you like to proceed with the mount (yes/no)? : yes
...
in order to avoid this warning in the future (yes/no)? : no 
Not adding sig to user sig cache file; continuing with mount.
Mounted eCryptfs
xb@dnxb:/tmp/test$ l /opt/data
total 8.0K
52953089 drwxr-xr-x 9 root root ? 4.0K Feb  27 23:16 ../
56369402 drwxr-xr-x 2 root root ? 4.0K Feb  27 23:16 ./
xb@dnxb:/tmp/test$ sudo touch /opt/data/testing
xb@dnxb:/tmp/test$ less /opt/data/testing      
xb@dnxb:/tmp/test$ sudo umount /opt/data
xb@dnxb:/tmp/test$ ls -ls /opt/data
total 8
8 -rw-r--r-- 1 root root 8192 Feb  27 23:42 ECRYPTFS_FNEK_ENCRYPTED.FWbECDhE0C37e-Skw2B2pnQpP9gB.b3yDfkVU5wk7WhvMreg8yVnuEaMME--
xb@dnxb:/tmp/test$ less /opt/data/ECRYPTFS_FNEK_ENCRYPTED.FWbECDhE0C37e-Skw2B2pnQpP9gB.b3yDfkVU5wk7WhvMreg8yVnuEaMME-- 
"/opt/data/ECRYPTFS_FNEK_ENCRYPTED.FWbECDhE0C37e-Skw2B2pnQpP9gB.b3yDfkVU5wk7WhvMreg8yVnuEaMME--" may be a binary file.  See it anyway? 
xb@dnxb:/tmp/test$ sudo mount -t ecryptfs /opt/data /opt/data
Passphrase: 
Select cipher: 
...
Selection [aes]: 1   
...
Selection [16]: 1
Enable plaintext passthrough (y/n) [n]: y
Enable filename encryption (y/n) [n]: y
...
Would you like to proceed with the mount (yes/no)? : yes
...
in order to avoid this warning in the future (yes/no)? : no 
Not adding sig to user sig cache file; continuing with mount.
Mounted eCryptfs
xb@dnxb:/tmp/test$ ls -ls /opt/data
total 8
8 -rw-r--r-- 1 root root 0 Feb  27 23:42 testing
xb@dnxb:/tmp/test$
files filesystems
  • 2 个回答
  • 1585 Views
Martin Hope
林果皞
Asked: 2018-01-20 08:18:00 +0800 CST

各种shell的fd数量是否固定?

  • 2

比方说:

xb@dnxb:/tmp$ echo 'ls -l /proc/$$/fd | grep a.sh' > a.sh; \
> while IFS='' read -r f; do \
> echo "$f"; "$f" a.sh; \
> done < <(tail -n +2 /etc/shells)
/bin/sh
lr-x------ 1 xiaobai xiaobai 64 Jan  20 00:09 10 -> /tmp/a.sh
/bin/dash
lr-x------ 1 xiaobai xiaobai 64 Jan  20 00:09 10 -> /tmp/a.sh
/bin/bash
lr-x------ 1 xiaobai xiaobai 64 Jan  20 00:09 255 -> /tmp/a.sh
/bin/rbash
lr-x------ 1 xiaobai xiaobai 64 Jan  20 00:09 255 -> /tmp/a.sh
/bin/zsh
lr-x------ 1 xiaobai xiaobai 64 Jan  20 00:09 11 -> /tmp/a.sh
/usr/bin/zsh
lr-x------ 1 xiaobai xiaobai 64 Jan  20 00:09 11 -> /tmp/a.sh
/bin/ksh93
lr-x------ 1 xiaobai xiaobai 64 Jan  20 00:09 10 -> /tmp/a.sh
/bin/rksh93
lr-x------ 1 xiaobai xiaobai 64 Jan  20 00:09 10 -> /tmp/a.sh
xb@dnxb:/tmp$ 

bash 是否始终具有固定的 fd 编号 255 而 zsh 默认具有固定的 fd 编号 11?

我问这个问题是因为我需要提取从任何 shell 进程执行的完整路径。我想知道我是否可以硬编码我的脚本来引用这个固定数字。

请注意,这是针对个人脚本,并不意味着在关键业务上运行,所以我不是在寻找 100% 可靠的,但fd 编号是否在大多数情况下都固定?

[更新]:

我不解析的cmdline原因是:

xb@dnxb:~/Downloads$ cat foo.sh 
#!/bin/bash
cat "/proc/$$/cmdline" | tr '\0' '\n'
readlink -f /proc/$$/fd/255

xb@dnxb:~/Downloads$ bash --norc foo.sh --norc
bash
--norc
foo.sh
--norc
/home/xiaobai/Downloads/foo.sh
xb@dnxb:~/Downloads$ 

如您所见,只能fd给出完整路径/home/xiaobai/Downloads/foo.sh,但不能给出cmdline. 并且脚本无法区分foo.sh或者--norc是路径或选项,因为foo.sh可以出现在任何选项位置,除非我进行丑陋的检查,例如它不是 startswith --。

虽然fd即使我这样做也没有问题产生正确的完整路径bash --norc foo.sh --norc foo2.sh。

无论如何,我刚刚意识到我的任务不必检查这个,因为我注意到除了自定义进程之外没有系统进程是从 shell 继承的。但仍然任何答案都会对未来的读者有所帮助。

bash shell
  • 2 个回答
  • 249 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