国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Linux shell編程學(xué)習(xí)筆記33:type 命令

這篇具有很好參考價(jià)值的文章主要介紹了Linux shell編程學(xué)習(xí)筆記33:type 命令。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

shell腳本type命令,Linux世界,麒麟操作系統(tǒng),編程資料,linux,腳本編程,linux腳本,type命令,內(nèi)置命令,外置命令,函數(shù)

?目錄

  1. 0?引言
  2. 1 type?命令的功能和格式
    1. 1.1?type命令的功能
    2. 1.2 type?命令的格式
  3. 2 type命令用法實(shí)例
    1. 2.1用type命令查看shell內(nèi)置命令(以echo命令為例)
    2. 2.2?用type命令查看別名(以ls命令為例)
    3. 2.3 用type命令同時(shí)查看shell內(nèi)置命令和別名(以echo和ls命令為例)
    4. 2.4?用type命令查看外部命令(以tty命令為例)
    5. 2.4?用type命令查看內(nèi)部命令、別名和外部命令(以echo、ls和tty命令為例)
    6. 2.5 用type 命令查看函數(shù)
    7. 2.6 如果我們用內(nèi)置命令或別名作為自

0?引言

在DOS中,type命令的功能是查看文件內(nèi)容。

而在Linux中,type命令的功能與DOS中的大相徑庭。

1 type?命令的功能和格式

我們可以使用 help type?命令查看 bash?中?關(guān)于type命令的幫助信息,其中包括了命令的功能?和格式。

purpleEndurer ?@ bash ~ $ help type
type: type [-afptP] name [name ...]
? ? Display information about command type.
? ??
? ? For each NAME, indicate how it would be interpreted if used as a
? ? command name.
? ??
? ? Options:
? ? ? -a ? ? ? ?display all locations containing an executable named NAME;
? ? ? ? includes aliases, builtins, and functions, if and only if
? ? ? ? the `-p' option is not also used
? ? ? -f ? ? ? ?suppress shell function lookup
? ? ? -P ? ? ? ?force a PATH search for each NAME, even if it is an alias,
? ? ? ? builtin, or function, and returns the name of the disk file
? ? ? ? that would be executed
? ? ? -p ? ? ? ?returns either the name of the disk file that would be executed,
? ? ? ? or nothing if `type -t NAME' would not return `file'.
? ? ? -t ? ? ? ?output a single word which is one of `alias', `keyword',
? ? ? ? `function', `builtin', `file' or `', if NAME is an alias, shell
? ? ? ? reserved word, shell function, shell builtin, disk file, or not
? ? ? ? found, respectively
? ??
? ? Arguments:
? ? ? NAME ? ? ?Command name to be interpreted.
? ??
? ? Exit Status:
? ? Returns success if all of the NAMEs are found; fails if any are not found.
typeset: typeset [-aAfFgilrtux] [-p] name[=value] ...
? ? Set variable values and attributes.
? ??
? ? Obsolete. ?See `help declare'.
purpleEndurer ?@ bash ~ $?

shell腳本type命令,Linux世界,麒麟操作系統(tǒng),編程資料,linux,腳本編程,linux腳本,type命令,內(nèi)置命令,外置命令,函數(shù)

?1.1?type命令的功能

type命令?可以顯示指定命令的信息,判斷給出的指令是內(nèi)部命令、外部命令(文件)、別名、函數(shù)、保留字 或者 不存在(找不到)。

1.2 type?命令的格式

type [-afptP]?命令1 [命令2?...]

選項(xiàng)

選項(xiàng) 說(shuō)明 備注
-a

顯示包含指定命令的可執(zhí)行文件的所有位置;

當(dāng)且僅當(dāng)未使用“-p”選項(xiàng)時(shí),包括別名、內(nèi)置函數(shù)和函數(shù)

all
-f 禁止 查找 shell 函數(shù) function
-p 如果給出的命令為外部指令,則顯示其絕對(duì)路徑 path
-P 強(qiáng)制對(duì)給合的每個(gè)命令進(jìn)行 PATH 搜索,即使它是別名,內(nèi)置命令,或函數(shù),并返回將被執(zhí)行的磁盤文件的名稱? ? ? ??
-t 當(dāng)給定的命令為別名, shell保留字、shell 函數(shù)、shell 內(nèi)置命令、外部命令(磁盤文)件或?未找到時(shí),分別輸出“alias”, “keyword”, “function”, “builtin”, “file”?或?空。 type

2 type命令用法實(shí)例

2.1用type命令查看shell內(nèi)置命令(以echo命令為例)

purpleEndurer ?@ bash ~ $ type            # 不接任何選項(xiàng)和參數(shù),無(wú)顯示
purpleEndurer ?@ bash ~ $ type echo       # 接命令,顯示命令類型
echo is a shell builtin
purpleEndurer ?@ bash ~ $ type -t echo    # 對(duì)內(nèi)部命令使用 -t 參數(shù),會(huì)顯示
                                          # builtin,表示其為內(nèi)部命令
builtin
purpleEndurer ?@ bash ~ $ type -p echo    # 對(duì)內(nèi)部命令使用 -p 參數(shù),無(wú)顯示
purpleEndurer ?@ bash ~ $ type -a echo    # 使用 -a 參數(shù),會(huì)將PATH變量中
                                          # 包含echo的命令顯示出來(lái)
echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echo
purpleEndurer  @ bash ~ $ echo $PATH      # 查看PATH變量的值
/home/csdn/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
purpleEndurer  @ bash ~ $ 

?shell腳本type命令,Linux世界,麒麟操作系統(tǒng),編程資料,linux,腳本編程,linux腳本,type命令,內(nèi)置命令,外置命令,函數(shù)

2.2?用type命令查看別名(以ls命令為例)

purpleEndurer ?@ bash ~ $ type ls
ls is aliased to `ls --color=auto'
purpleEndurer ?@ bash ~ $ type -t ls
alias
purpleEndurer ?@ bash ~ $ type -p ls
purpleEndurer ?@ bash ~ $ type -a ls
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
ls is /bin/ls
purpleEndurer ?@ bash ~ $?

shell腳本type命令,Linux世界,麒麟操作系統(tǒng),編程資料,linux,腳本編程,linux腳本,type命令,內(nèi)置命令,外置命令,函數(shù)

?如果我們想執(zhí)行真正的那個(gè)命令而非別名,除了用

Linux shell編程學(xué)習(xí)筆記31:alias 和 unalias 操作 命令別名https://blog.csdn.net/Purpleendurer/article/details/134642886?spm=1001.2014.3001.5501

中的介紹的方法,還可以用type命令來(lái)判斷。

2.3 用type命令同時(shí)查看shell內(nèi)置命令和別名(以echo和ls命令為例)

purpleEndurer ?@ bash ~ $ type echo ls
echo is a shell builtin
ls is aliased to `ls --color=auto'

purpleEndurer ?@ bash ~ $ type -t echo ls
builtin
alias
purpleEndurer ?@ bash ~ $ type -p echo ls
purpleEndurer ?@ bash ~ $ type -a echo ls
echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echo
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
ls is /bin/ls

purpleEndurer ?@ bash ~ $

?shell腳本type命令,Linux世界,麒麟操作系統(tǒng),編程資料,linux,腳本編程,linux腳本,type命令,內(nèi)置命令,外置命令,函數(shù)

2.4?用type命令查看外部命令(以tty命令為例)

purpleEndurer ?@ bash ~ $ type tty
tty is /usr/bin/tty
purpleEndurer ?@ bash ~ $ type -p tty
/usr/bin/tty
purpleEndurer ?@ bash ~ $ type -P tty
/usr/bin/tty
purpleEndurer ?@ bash ~ $ type -t tty
file
purpleEndurer ?@ bash ~ $ type -a tty
tty is /usr/bin/tty
tty is /bin/tty
purpleEndurer ?@ bash ~ $ type -ap tty
/usr/bin/tty
/bin/tty
purpleEndurer ?@ bash ~ $ type -apt tty
file
file
purpleEndurer ?@ bash ~ $?

shell腳本type命令,Linux世界,麒麟操作系統(tǒng),編程資料,linux,腳本編程,linux腳本,type命令,內(nèi)置命令,外置命令,函數(shù)

2.4?用type命令查看內(nèi)部命令、別名和外部命令(以echo、ls和tty命令為例)

purpleEndurer ?@ bash ~ $ type echo ls tty
echo is a shell builtin
ls is aliased to `ls --color=auto'
tty is /usr/bin/tty
purpleEndurer ?@ bash ~ $ type -apt echo ls tty
builtin
file
file
alias
file
file
file
file
purpleEndurer ?@ bash ~ $ type -a echo ls tty
echo is a shell builtin
echo is /usr/bin/echo
echo is /bin/echo
ls is aliased to `ls --color=auto'
ls is /usr/bin/ls
ls is /bin/ls
tty is /usr/bin/tty
tty is /bin/tty
purpleEndurer ?@ bash ~ $ type -at echo ls tty
builtin
file
file
alias
file
file
file
file
purpleEndurer ?@ bash ~ $ type -t echo ls tty
builtin
alias
file
purpleEndurer ?@ bash ~ $ type -p echo ls tty
/usr/bin/tty
purpleEndurer ?@ bash ~ $?

shell腳本type命令,Linux世界,麒麟操作系統(tǒng),編程資料,linux,腳本編程,linux腳本,type命令,內(nèi)置命令,外置命令,函數(shù)

2.5 用type 命令查看函數(shù)

我們先定義一個(gè)函數(shù):

function a()
{
  echo hello;
}

然后用type命令來(lái)查看:

purpleEndurer @ bash ~ $ function a(){ echo hello; }
purpleEndurer @ bash ~ $ type a
a is a function
a ()?
{?
? ? echo hello
}
purpleEndurer @ bash ~ $ type -a a
a is a function
a ()?
{?
? ? echo hello
}
purpleEndurer @ bash ~ $ type -f a
bash: type: a: not found
purpleEndurer @ bash ~ $ type -t a
function
purpleEndurer @ bash ~ $ type -p a
purpleEndurer @ bash ~ $ type -P a
purpleEndurer @ bash ~ $??

shell腳本type命令,Linux世界,麒麟操作系統(tǒng),編程資料,linux,腳本編程,linux腳本,type命令,內(nèi)置命令,外置命令,函數(shù)

可見(jiàn),-p和-P選項(xiàng)對(duì)函數(shù)沒(méi)有作用。

2.6 如果我們用內(nèi)置命令或別名作為自定義函數(shù)名,type命令會(huì)如何顯示?

我們先定義一個(gè)函數(shù):

function ls()
{
  echo hello;
}

然后用type命令來(lái)查看:

purpleEndurer @ bash ~ $ function ls(){ echo hello; }
purpleEndurer @ bash ~ $ ls
hello
purpleEndurer @ bash ~ $ type ls
ls is aliased to `ls --color=auto'
purpleEndurer @ bash ~ $ type -a ls?
ls is aliased to `ls --color=auto'
ls is a function
ls ()?
{?
? ? echo hello
}
ls is /usr/bin/ls
ls is /bin/ls
purpleEndurer @ bash ~ $ type -t ls?
alias
purpleEndurer @ bash ~ $ type -p ls?
purpleEndurer @ bash ~ $?

shell腳本type命令,Linux世界,麒麟操作系統(tǒng),編程資料,linux,腳本編程,linux腳本,type命令,內(nèi)置命令,外置命令,函數(shù)

從上面的命令執(zhí)行情況來(lái)看:文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-768423.html

  • 就執(zhí)行優(yōu)先級(jí)而言,函數(shù)優(yōu)先于內(nèi)置命令。
  • 不加任何選項(xiàng)的話,type命令 不對(duì)函數(shù)進(jìn)行處理。
  • 使用 -a 選項(xiàng),type命令 才對(duì)函數(shù)進(jìn)行處理。

到了這里,關(guān)于Linux shell編程學(xué)習(xí)筆記33:type 命令的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Linux shell編程學(xué)習(xí)筆記39:df命令

    Linux shell編程學(xué)習(xí)筆記39:df命令

    0 前言 1? df命令的功能、格式和選項(xiàng)說(shuō)明 1.1 df命令的功能 1.2 df命令的格式 1.3 df命令選項(xiàng)說(shuō)明? 2 df命令使用實(shí)例? 2.1? df:顯示主要文件系統(tǒng)信息 2.2 df -a:顯示所有文件系統(tǒng)信息 2.3 df?-t[=]TYPE或--type[=]TYPE:顯示TYPE指定類型的文件系統(tǒng)信息 2.4?df --total:追加顯示統(tǒng)計(jì)信息 2

    2024年01月16日
    瀏覽(28)
  • Linux shell編程學(xué)習(xí)筆記41:lsblk命令

    Linux shell編程學(xué)習(xí)筆記41:lsblk命令

    邊緣計(jì)算面臨著數(shù)據(jù)安全與隱私保護(hù)、網(wǎng)絡(luò)穩(wěn)定性等挑戰(zhàn),但同時(shí)也帶來(lái)了更強(qiáng)的實(shí)時(shí)性和本地處理能力,為企業(yè)降低了成本和壓力,提高了數(shù)據(jù)處理效率。因此,邊緣計(jì)算既帶來(lái)了挑戰(zhàn)也帶來(lái)了機(jī)遇,需要我們不斷地研究 前幾節(jié)學(xué)習(xí)我們均涉及到磁盤和文件存儲(chǔ),今天我們

    2024年01月24日
    瀏覽(27)
  • Linux shell編程學(xué)習(xí)筆記47:lsof命令

    Linux shell編程學(xué)習(xí)筆記47:lsof命令

    今天國(guó)產(chǎn)電腦提示磁盤空間已耗盡,使用用df命令檢查文件系統(tǒng)情況,發(fā)現(xiàn)/dev/sda2已使用100%。 Linux shell編程學(xué)習(xí)筆記39:df命令 https://blog.csdn.net/Purpleendurer/article/details/135577571 于是開(kāi)始清理磁盤空間。 第一步是查看已刪除、但空間卻沒(méi)有釋放的進(jìn)程。 這里要用到 lsof命令。

    2024年04月27日
    瀏覽(15)
  • Linux shell編程學(xué)習(xí)筆記36:read命令

    Linux shell編程學(xué)習(xí)筆記36:read命令

    ?*更新日志? *2023-12-18 1.根據(jù)[美] 威廉·肖特斯 (Willian?shotts)所著《Linux命令行大全(第2版)》 ? ? ? ? ? ? ? ? ? ? ? ? 更新了-e、-i、-r選項(xiàng)的說(shuō)明 ? ? ? ? ? ? ? ? ? ? ? 2.更新了 2.8 的實(shí)例,增加了gif動(dòng)圖 ? ? ? ? ? ? ? ? ? ? ? 3.補(bǔ)充了-i的應(yīng)用實(shí)例 2.12 目錄 目錄

    2024年02月04日
    瀏覽(24)
  • Linux shell編程學(xué)習(xí)筆記37:readarray命令和mapfile命令

    Linux shell編程學(xué)習(xí)筆記37:readarray命令和mapfile命令

    ? 目錄 ? 0 前言 1? readarray命令的格式和功能 1.1 命令格式 1.2?命令功能 1.3?注意事項(xiàng) 2?命令應(yīng)用實(shí)例 2.1 從標(biāo)準(zhǔn)輸入讀取數(shù)據(jù)時(shí)不指定數(shù)組名,則數(shù)據(jù)會(huì)保存到MAPFILE數(shù)組中 2.2 從標(biāo)準(zhǔn)輸入讀取數(shù)據(jù)并存儲(chǔ)到指定的數(shù)組 2.3?使用 -O?選項(xiàng)指定起始下標(biāo) 2.4?用-n指定有效行數(shù) 2.5?

    2024年02月03日
    瀏覽(24)
  • Linux shell編程學(xué)習(xí)筆記45:uname命令-獲取Linux系統(tǒng)信息

    Linux shell編程學(xué)習(xí)筆記45:uname命令-獲取Linux系統(tǒng)信息

    linux 有多個(gè)發(fā)行版本,不同的版本都有自己的版本號(hào)。 如何知道自己使用的Linux的系統(tǒng)信息呢? 使用uname命令、hostnamectl命令,或者通過(guò)查看/proc/version文件來(lái)了解這些信息。 我們先看看uname命令。 我們可以使用命令 uname --help命令 查看它的用法: purpleEndurer @ ?bash ~ $ uname --

    2024年04月10日
    瀏覽(26)
  • Linux shell編程學(xué)習(xí)筆記6:查看和設(shè)置變量的常用命令

    Linux shell編程學(xué)習(xí)筆記6:查看和設(shè)置變量的常用命令

    上節(jié)我們介紹了變量的變量命名規(guī)則、變量類型、使用變量時(shí)要注意的事項(xiàng),今天我們學(xué)習(xí)一下查看和設(shè)置變量的一些常用命令,包括變量的提升,有些命令在之前的實(shí)例中已經(jīng)使用過(guò)了。 語(yǔ)法格式:echo [參數(shù)] [輸出內(nèi)容] 常用參數(shù): -e:支持反斜線控制的字符轉(zhuǎn)換(具體參

    2024年02月07日
    瀏覽(22)
  • Linux shell編程學(xué)習(xí)筆記31:alias 和 unalias 操作 命令別名

    Linux shell編程學(xué)習(xí)筆記31:alias 和 unalias 操作 命令別名

    目錄 0?前言 1 定義別名 2?查看別名 2.1?查看所有別名 2.2?查看某個(gè)別名 2.2.1? alias?別名 2.2.2 alias | grep?別名字符串 2.2.3?使用 Ctrl+Alt+E 組合鍵 3 unalias:刪除別名 4 如何執(zhí)行命令本身而非別名 4.1 方法1:使用 Ctrl+Alt+E 組合鍵? unalias 4.2 方法2:在命令前加上命令文件的絕對(duì)路徑

    2024年02月05日
    瀏覽(28)
  • Linux shell編程學(xué)習(xí)筆記46:awk命令的由來(lái)、功能、格式、選項(xiàng)說(shuō)明、版權(quán)、版本

    Linux shell編程學(xué)習(xí)筆記46:awk命令的由來(lái)、功能、格式、選項(xiàng)說(shuō)明、版權(quán)、版本

    在編寫(xiě)Linux Shell腳本的過(guò)程中,我們經(jīng)常要對(duì)Linux命令執(zhí)行的結(jié)果進(jìn)行分析和提取,Linux也在文本分析和提取這方面提供了不少的命令。比如我們之前研究過(guò)的cut命令。 Linux shell編程學(xué)習(xí)筆記43:cut命令 https://blog.csdn.net/Purpleendurer/article/details/135730679?spm=1001.2014.3001.5501 除了cut命

    2024年04月24日
    瀏覽(16)
  • Linux 系統(tǒng)shell腳本編程筆記——腳本入門

    Linux 系統(tǒng)shell腳本編程筆記——腳本入門

    目錄 1、創(chuàng)建shell腳本文件 ?2、顯示消息 3、?環(huán)境變量 4、用戶變量 5、命令替換 ?編輯 ?6、重定向輸入與輸出 6.1、輸出重定向 ?6.2、輸入重定向 ?編輯 7、執(zhí)行數(shù)學(xué)運(yùn)算 7.1、expr命令 7.2、bc的基本用法 ?8、退出腳本 完整筆記請(qǐng)前往此處獲取:https://download.csdn.net/download/qq

    2024年02月06日
    瀏覽(28)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包