1 | shopt
|
2 | ===
|
3 |
|
4 | 显示和设置shell操作选项
|
5 |
|
6 | ## 补充说明
|
7 |
|
8 | **shopt命令** 用于显示和设置shell中的行为选项,通过这些选项以增强shell易用性。shopt命令若不带任何参数选项,则可以显示所有可以设置的shell操作选项。
|
9 |
|
10 | ### 语法
|
11 |
|
12 | ```shell
|
13 | shopt(选项)(参数)
|
14 | ```
|
15 |
|
16 | ### 选项
|
17 |
|
18 | ```shell
|
19 | -s:激活指定的shell行为选项;
|
20 | -u:关闭指定的shell行为选项。
|
21 | ```
|
22 |
|
23 | ### 参数
|
24 |
|
25 | shell选项:指定要操作的shell选项。
|
26 |
|
27 | ### 实例
|
28 |
|
29 | 使用shopt命令显示当前所有可以设置的shell操作选项,输入如下命令:
|
30 |
|
31 | ```shell
|
32 | shopt #输出所有可以设置的shell操作选项
|
33 | cdable_vars off
|
34 | cdspell off
|
35 | checkhash off
|
36 | checkwinsize on
|
37 | cmdhist on
|
38 | dotglob off
|
39 | execfail off
|
40 | expand_aliases on
|
41 | extdebug off
|
42 | ...
|
43 | ```
|
44 |
|
45 | 如图上所示,选项"cdspell"的状态为"off",即关闭cd拼写检查选项。现在,可以使用shopt命令将其开启,输入如下命令:
|
46 |
|
47 | ```shell
|
48 | shopt -s cdspell #开启cd拼写检查
|
49 | ```
|
50 |
|
51 | 执行上面的命令后,该选项的状态将变为"on",即开启状态。可以再次通过该命令显示一下shell操作选项即可,输出信息如下:
|
52 |
|
53 | ```shell
|
54 | cdspell on #开启cdspell选项
|
55 | ```
|
56 |
|
57 | 用户可以通过实际执行cd命令检查该选项是否被成功开启。
|
58 |
|
59 |
|