Learning BASH 1

 開始看一本叫做learning the bash SHELL的書.

不知道爲什麼,看那些翻譯過來的書老是讓我想睡覺,覺得很無聊。

看看英文書,覺得很多概念都很淺顯易懂(纔看了幾頁的感覺。),既可以學技術,又可以學新單詞。。一舉兩得

今天開始看getting bash

echo $SHELL #查看當前的shell 版本

我這臺機器是csh

輸入bash若能進入一個類似bash-3.00$的界面,代表系統有bash,如果是not found,可能是bash裝在了一個你無法訪問的文件夾,或者其他原因。

如何將bash作爲login shell?

首先找出bash的安裝目錄,csh下可以輸入

whereis bash 其他情況下可以輸入whence bash,which bash

雖然我的環境是csh,但是用whereis和whence都提示Command not found,用which bash找到了

/usr/bin/bash

然後輸入chsh bash-name

如無意外,就會提示輸入密碼。輸入密碼後登出再登入系統就可以開始使用bash了。

不知道是不是我這個用戶沒有權限,我輸入上面的指令提示

chsh: Command not found

google 了下,原來On some systems chsh is a hard link to /usr/bin/passwd. Since chsh is not POSIX, it won't be on all systems, so try the passwd approach if you do not have chsh.

我的機器solaris沒有裝chsh,不得已我只好手動修改/etc/passwd文件,將root用戶的最後一列修改爲bash的路徑。登出系統再登陸就看到login shell已經改回來了。

當然手動修改passwd文件是不推薦的,並且還需要root權限。最好還是安裝chsh。

 

開始Interactive Shell Use

一個指令如lp myfile lp是命令(打印一個文件),myfile是argument。arguments通常是文件名,也會是username,如mail cam,cam就是username

option是特殊的argument,通常是一個dash(-)後跟一個字母,但是這並不是一個硬性規定(hard-and-fast rule.)

如lp -h myfile, -h告訴lp不要打印“banner page”

有時某些option也會有自己的arguments,如

lp -d lp1 -h myfile 有兩個option一個argument。

第一個option是-d lp1,意思是把結果傳遞給lp1打印機(send the output to the printer(destination) called lp1)

第二個option仍爲-h

 

文件 Files

作爲UNIX系統中最重要的東西,文件中最重要的三類如下

regular files:也叫text files,包含可讀寫字符

executable files:也叫program,作爲指令調用。

directories:

 最頂端的文件夾叫做root,在系統中沒有名字。

full pathnames 以/開始

THE WORKING DIRECTORY(the current directory)

relative pathnames,不以/開頭,文件路徑相對於當前所在目錄。

登陸系統後,所在位置叫做home directory

bash使用 tilde(~)符號代表home directory:~username如指向用戶alice的文件story可以這樣表示

~alice/story #這是絕對路徑

一個單獨的~代表所登陸用戶自己的 home 目錄。

如訪問root(登陸用戶的文件notes)~/notes

使用~是非常方便的,特別是當你的working 目錄不在home目錄時,如在/tmp

cd change working 目錄

pwd 打印working目錄

如果cd沒有argument的話,則是回到home 目錄,相當於cd ~

cd - 回到上次所在的目錄。

 

 

 

 

hard-and-fast 

If you say that there are no hard and fast rules, or that there is no hard and fast information about something, you are indicating that there are no fixed or definite rules or facts.
There are no hard and fast rules, but rather traditional guidelines as to who pays for what. 

hierarchical  
hierarchical
A hierarchical system or organization is one in which people have different ranks or positions, depending on how important they are.
...the traditional hierarchical system of military organization. 
oval  
oval 橢圓形
Oval things have a shape that is like a circle but is wider in one direction than the other. 
 
tilde notation
tilde  顎化符號 (~)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章