菜鳥教程:全面學(xué)習(xí) pwd 命令
10.設(shè)置多行顯示 (就像下面這樣),
/home123#Hello#!
接著執(zhí)行命令(比如說(shuō)ls)來(lái)檢驗(yàn)一切OK。
avi@tecmint:~$ PS1='> $PWD$ 123#Hello#!$ ' /home123#Hello#!
![Set Multi Commandline Prompt](http://editerupload.eepw.com.cn/fetch/20160912/304208_2_0.jpg)
設(shè)置多行顯示
11.一下子檢查當(dāng)前工作路徑以及先前的工作路徑。
avi@tecmint:~$ echo “$PWD $OLDPWD”/home /home/avi
![Check Present Previous Working Directory](http://editerupload.eepw.com.cn/fetch/20160912/304208_2_1.jpg)
檢查當(dāng)前工作路徑
12.pwd文件的絕對(duì)路徑(以/開始)。
/bin/pwd
13.pwd源文件文件的絕對(duì)路徑(以/開始)。
/usr/include/pwd.h
13.pwd手冊(cè)的絕對(duì)路徑(以/開始)。
/usr/share/man/man1/pwd.1.gz
15.寫一個(gè)shell腳本分析home目錄下的一個(gè)目錄(比如tecmint)。如果當(dāng)前目錄是tecmint就輸出“Well! You are in tecmint directory”接著輸出“Good Bye”,不然就在tecmint下面創(chuàng)建一個(gè)目錄并提示你cd進(jìn)入它。
讓我們首先創(chuàng)建一個(gè)‘tecmint’目錄,在下面創(chuàng)建一個(gè)名為‘pwd.sh’的腳本文件。
avi@tecmint:~$ mkdir tecmintavi@tecmint:~$ cd tecmintavi@tecmint:~$ nano pwd.sh
接下來(lái)在pwd.sh中加入下面的腳本。
#!/bin/bash x=$(pwd)if [ $x == /home/$USER/tecmint ]then{echo Well you are in tecmint directoryecho Good Bye}else{mkdir /home/$USER/tecmintecho Created Directory tecmint you may now cd to it}fi
給予執(zhí)行權(quán)限并運(yùn)行。
avi@tecmint:~$ chmod 755 pwd.shavi@tecmint:~$ ./pwd.shWell you are in tecmint directoryGood Bye
評(píng)論