我有以下两个测试文件:
test1 test2
Run Code Online (Sandbox Code Playgroud)
两者都是空白。现在我发出以下命令:
$ cat > test1
Run Code Online (Sandbox Code Playgroud)
Enter
This is a test file
Run Code Online (Sandbox Code Playgroud)
Enter
Ctrl + D
$ cat > test2
Run Code Online (Sandbox Code Playgroud)
Enter
This is another test file
Run Code Online (Sandbox Code Playgroud)
Enter
^C
Run Code Online (Sandbox Code Playgroud)
Ctrl + C
$
Run Code Online (Sandbox Code Playgroud)
现在我检查两个文件的内容
$ cat test1
This is a test file
$ cat test2
This is another test file
$
Run Code Online (Sandbox Code Playgroud)
那么如果我们使用上述两种方法来达到相同的结果,结果有什么真正的区别吗?
我的工作目录中有以下两个文件:
test.txt
和img.jpg
test.txt
是一个字符特殊文件
img.jpg
是一个块特殊文件
现在我想使用 shell 脚本查找这些文件是字符特殊文件还是块特殊文件。
我写了以下两个shell脚本:
第一的-
#! /bin/bash
echo -e "Enter file name: \c"
read file_name
if [ -c $file_name ]
then
echo Character special file $file_name found
else
echo Character special file $file_name not found
Run Code Online (Sandbox Code Playgroud)
输入:
test.txt
Run Code Online (Sandbox Code Playgroud)
输出:
Character special file test.txt not found
Run Code Online (Sandbox Code Playgroud)
第二-
#! /bin/bash
echo -e "Enter file name: \c"
read file_name
if [ -b $file_name ]
then
echo Block special file $file_name found
else
echo Block special file …
Run Code Online (Sandbox Code Playgroud)