ALZ*_*ALZ 12 command-line bash job-control exit background-process
我有一个练习将一些数据(来自某些目录的 *conf)放入一个文件中,并且需要在后台执行此操作。我做到了,我想知道输出消息的含义是什么:
[A@localhost tests]$ ls -ld /etc/*conf /usr/*conf > test1_6_conf.txt 2>&1 &
Run Code Online (Sandbox Code Playgroud)
输入上升到这一行:
[1] 2533
Run Code Online (Sandbox Code Playgroud)
这是什么意思?在其他 Enter 之后,会出现另一条消息
[A@localhost tests]$
[1]+ Exit 2 ls --color=auto -ld /etc/*conf /usr/*conf > test1_6_conf.txt 2>&1
Run Code Online (Sandbox Code Playgroud)
这是什么意思?什么是“出口2”?
输入检查结果 - 似乎一切正常。
[A@localhost tests]$
[A@localhost tests]$ ls -l test1_6_conf.txt
-rw-rw-r--. 1 A A 2641 Nov 22 14:19 test1_6_conf.txt
[A@localhost tests]$
Run Code Online (Sandbox Code Playgroud)
我正在使用 CentOS 6.4,Gnome 终端模拟器。
小智 18
这是什么意思?什么是“出口2”?
它是 的退出状态ls。ls 见 man:
Exit status:
0 if OK,
1 if minor problems (e.g., cannot access subdirectory),
2 if serious trouble (e.g., cannot access command-line argument).
Run Code Online (Sandbox Code Playgroud)
我想原因是你有很多 *conf 文件,/etc而 /usr 中没有 *conf 文件。事实上ls -ld /usr/*conf;会产生同样的效果。
因此,如果我在计算机上ls对现有文件进行操作:
ls main.cpp; echo $?
main.cpp
0
Run Code Online (Sandbox Code Playgroud)
对于不存在的文件:
ls main.cppp; echo $?
ls: cannot access main.cppp: No such file or directory
2
Run Code Online (Sandbox Code Playgroud)
或者作为不存在的文件的后台进程 ls:
>ls main.cppp &
[1] 26880
ls: cannot access main.cppp: No such file or directory
[1]+ Exit 2 ls main.cppp
Run Code Online (Sandbox Code Playgroud)