Linux 脚本执行:由一个补丁分析说起

事情背景 补丁链接:a4ae32c71fe9 (“exec: Always set cap_ambient in cap_bprm_set_creds”) 补丁信息中提到,该补丁是为了确保 cap_bprm_set_creds() 每次都会设置 cap_ambient 变量。另外还提到了下述内容: … if there is a suid or sgid script with an interpreter that has neither the suid nor the sgid bits set the interpreter should be able to accept …

"Tricks and Craft" in Bash Scripting

Process Input Line by Line 1#!/bin/bash 2input="path/to/file" 3while IFS= read -r line 4do 5 # process each read-in line 6 echo "$line" 7done < "$input" # NORICE HERE Pay attention to the < part following done on the last line. It redirects the $input file to stdin of read process, making …

一个简洁实用的进入 Chroot 环境的脚本

之前在某处看到了这么一份用于进入 Chroot 环境的 Bash 脚本,感觉不错就收藏了。先贴一下原始脚本: 1#!/bin/bash 2 3CHROOT_DIR=$(dirname $(readlink -f $0)) 4 5USAGE=" 6Usage: sh $0 [option] 7 8Warning: This script cannot be used in compile_env 9Options: 10 init init compile_env and mount the required directories 11 no option default to init 12 umount clean up …

Linux 中查看某程序的路径

查看一个程序的完整路径,除了可以了解其是否存在及所处的位置,还有更重要的作用:当系统中有多个同名程序安装在不同目录下时,检查程序的完整路径可以帮助我们确认其是否为我们想要执行的那个。在 Linux 系统中,我习惯使用 which 或 whereis 来查看一个命令的完整路径。 1$ which gcc 2/usr/bin/gcc 但有一天,我遇到了一个情况:程序明明可以在 Bash 里执行,但 which 就是找不到它。后来搜索到这条回答 才了解到,对路径中可能带有的一些特殊符号(如常用的 ~)而言,Bash 会在执行前解析并替换它们;而 which 却不会。因此,若是在 .bashrc 中写入 1export …