command 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

command 命令补充说明:


command命令 调用指定的指令并执行,命令执行时不查询 shell 函数。command 命令只能够执行 shell 内部的命令

[root@TestMaster ~]
# type command
command is a shell builtin

command 命令语法:


command(参数)

command 命令选项:


command [-p] [-v] [-V] command [arg ...]
            Execute the specified command but ignore shell functions when searching for it.
            (This is useful when you have a shell function with the same name as a builtin com‐
            mand.)

            -p     search for command using a PATH that guarantees to find all the standard util‐
                   ities.

            -V     Do not execute the command but search for the command and print the resolution
                   of the command search.  This is the same as the type builtin.

            -v     Do not execute the command but search for the command and print the absolute
                   pathname of utilities, the name for builtins or the expansion of aliases.

command 命令参数:


指令:需要调用的指令及参数。

command 命令实例:


使用command命令调用执行echo Linux,输入如下命令:

command echo Linux            #调用执行shell内部指令
#上面的命令执行后,将调用执行命令echo Linux,其执行结果如下:
Linux

写一个 Shell 脚本,test.sh 中构建 ls 函数,大家就可以体会 command 命令的作用:

#!/bin/bash

function ls()
{
    echo "CommandNotFound,发音:坑否"
}

echo "--1--"
ls

echo "--2--"
command ls

echo "--3--"
echo command ls

echo "--4--"
$(echo command ls)

--------------
#给脚本增加执行权限,并 test.sh,对比结果

下面是执行结果:

[root@TestMaster /Data]
# ./test.sh 
--1--
CommandNotFound,发音:坑否
--2--
Android  apps  del_kworderds.sh  ffmpeg_compress.sh  ffmpeg_travel_debug.sh  logs  SSP.proto  test.sh  tools  webapps
--3--
command ls
--4--
Android  apps  del_kworderds.sh  ffmpeg_compress.sh  ffmpeg_travel_debug.sh  logs  SSP.proto  test.sh  tools  webapps


command 命令评论

共收录到 489Linux 命令