Today, when writing a shell script, you want to use a CD to enter the Xargs pipeline output directory, but prompted the error. Details are as follows:
"Environment description"
Directory structure:
[Root@test1 nagiosclient_db]# ls-ltr
Total 2488
-rw-r--r--. 1 root 405725 Mar 3 14:12 nrpe-2.12.tar.gz
-rw-r--r--. 1 root 2095419 Mar 3 14:12 nagios-plugins-1.4.15.tar.gz
Drwxrwxrwx. 501 root 4096 Mar 3 14:36 nagios-plugins-1.4.15
Drwxrwxr-x. 7 4096 Mar 3 14:37 nrpe-2.12
Get the directory you want:
[Root@test1 nagiosclient_db]# ls | Egrep ' nrpe-[0-9]. [0-9]+.$ '
nrpe-2.12
To enter a specified directory using a pipe:
[Root@test1 nagiosclient_db]# ls | Egrep ' nrpe-[0-9]. [0-9]+.$ ' | Xargs Ls-ld | Xargs CD
Xargs:cd:No such file or directory
Encountered an error prompt.
To modify the command:
[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
entered the specified directory.
"Why the CD command cannot enter the directory for Xargs pipeline output"
Xargs involves writing pipes, while CDs are internal commands. Concrete involves the workings of the shell.
To view the absolute path of the CD command:
[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)
To view the absolute commands for Xargs:
[Root@test1 nrpe-2.12]# which Xargs
/usr/bin/xargs
Details such as the above, because of the non-system engineers, so the shell's principle does not do in-depth research.
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/
Author: csdn Blog Jason_asia