Today, when writing a shell script, I want to use a CD to enter the Xargs pipeline output directory, but prompted an error. Details are as follows:
"Environment description"
Directory structure:
[Email protected] 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. 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:
[[email protected] nagiosclient_db]# ls | Egrep ' nrpe-[0-9]. [0-9]+.$ '
nrpe-2.12
Use the pipeline to enter the specified directory:
[[email protected] 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 a command:
[[Email protected] nagiosclient_db]# CD "' ls | Egrep ' nrpe-[0-9]. [0-9]+.$ ']
[Email protected] nrpe-2.12]# pwd
/home/monitor/nagiosclient_db/nrpe-2.12
entered the specified directory.
"Why does the CD command not go to the Xargs pipeline output directory"
Xargs involves writing pipelines, while CDs are internal commands. Specifically involved in how the shell works.
To view the absolute path of the CD command:
[[email protected] 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 Xargs's absolute commands:
[email protected] nrpe-2.12]# which Xargs
/usr/bin/xargs
For details, as a non-system engineer, there is no in-depth study of the Shell's principles.
"Reference link"
Http://bbs.chinaunix.net/thread-750335-2-1.html
http://blog.csdn.net/jason_asia/article/details/28407189