有人可以解释一下这段代码在做什么吗?
if [ -f "saved.txt" ]; then // What does -f do?
rm saved.txt
fi
in=$(echo "{query}" | tr -d "\\") // How does this work?
// What does | tr -d "\\" mean?
echo "$in" > saved.txt // Is this simply putting the
// value of $in into saved.txt?
最佳答案
最初的 if 语句将测试该文件是否是常规文件。更多关于file test operators here .
此脚本将回显字符 {query}
并将其传送到命令 tr
,该命令使用 -d
将删除那些字符被指定。 tr
代表翻译。在这种情况下,它需要一个 SET,并且根据手册页,如果您使用 \\
,它将删除反斜杠。
结果存储在$in
中。
最后将存储在in
中的结果输出到saved.text
中。
NAME tr - translate or delete characters
SYNOPSIS tr [OPTION]... SET1 [SET2]
DESCRIPTION Translate, squeeze, and/or delete characters from standard input, writing to standard output.
-c, -C, --complement first complement SET1 -d, --delete delete characters in SET1, do not translate -s, --squeeze-repeats replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that character -t, --truncate-set1 first truncate SET1 to length of SET2 --help display this help and exit --version output version information and exit SETs are specified as strings of characters. Most represent themselves. Interpreted sequences are: \NNN character with octal value NNN (1 to 3 octal digits) \\ backslash
关于bash - 什么是 | tr -d 在 bash 中做什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22390167/