本篇內容介紹了“為什么Linux系統中cd無法進入xargs管道輸出的目錄 ”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
今天在寫shell腳本的時候,想用cd進入xargs管道輸出的目錄,但是提示報錯。詳情如下:
【環境描述】
目錄結構:
[root@test1 nagiosclient_db]# ls -ltr
total 2488
-rw-r--r--. 1 root root 405725 Mar 3 14:12 nrpe-2.12.tar.gz
-rw-r--r--. 1 root root 2095419 Mar 3 14:12 nagios-plugins-1.4.15.tar.gz
drwxrwxrwx. 16 501 root 4096 Mar 3 14:36 nagios-plugins-1.4.15
drwxrwxr-x. 7 500 500 4096 Mar 3 14:37 nrpe-2.12
獲取需要的目錄:
[root@test1 nagiosclient_db]# ls | egrep 'nrpe-[0-9].[0-9]+.$'
nrpe-2.12
使用管道進入指定的目錄:
[root@test1 nagiosclient_db]# ls | egrep 'nrpe-[0-9].[0-9]+.$' | xargs ls -ld | xargs cd
xargs: cd: No such file or directory
遇到報錯提示。
修改命令:
[root@test1 nagiosclient_db]# cd "`ls | egrep 'nrpe-[0-9].[0-9]+.$' `"
[root@test1 nrpe-2.12]# pwd
/home/monitor/nagiosclient_db/nrpe-2.12
進入了指定的目錄。
【為什么cd命令不能進入xargs管道輸出的目錄】
xargs牽涉寫管道,而cd是內部命令。具體的牽涉shell的工作原理。
查看cd命令的絕對路徑:
[root@test1 nrpe-2.12]# which cd
/usr/bin/which: no cd in (/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
查看xargs的絕對命令:
[root@test1 nrpe-2.12]# which xargs
/usr/bin/xargs
“為什么Linux系統中cd無法進入xargs管道輸出的目錄 ”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。