天天看點

shell 之hello world

以前接觸linux的比較少,比較常用的幾個指令能夠使用,接下來的項目中需要使用Linux,是以最近希望能夠增強一點Linux的知識,那麼就從hello world開始吧

第一步:了解Linux檔案的權限

[root@ibm mwq]# ls -l

總用量 8

drwxr-xr-x. 2 root root 4096  6月 25 17:35 hello

-rwxr--r--. 1 root root   33  6月 25 17:56 hello.awk

-rw-r--r--. 1 root root    0  6月 25 17:35 hello.txt

以上中對于hello目錄,其第一位為d,對于檔案,其第一位為-(短橫線),短橫線表示缺少權限,r為讀,w為寫,x表示可以進入目錄或者可以執行檔案。

第二步:了解chmod(change mode)指令,可以改變檔案的權限,現在了解一下指令的含義

[root@ibm mwq]# chmod u+x hello.awk

使用man chmod可以看到以下資訊

寫道

The letters rwxXst select file mode bits for the affected users: read (r), write (w), execute (or search for directories) (x), execute/search only if the file is a directory

or already has execute permission for some user (X), set user or group ID on execution (s), restricted deletion flag or sticky bit (t). Instead of one or more of these let-

ters, you can specify exactly one of the letters ugo: the permissions granted to the user who owns the file (u), the permissions granted to other users who are members of the

file’s group (g), and the permissions granted to users that are in neither of the two preceding categories (o).

該指令可以使檔案可執行

第三步:通過vim hello.awk編輯檔案

輸入以下内容

#!/bin/sh

echo "hello,world!"

“#!”稱為幻數,“#!/bin/sh”表示通過bin/sh進行檔案内容的解釋

那麼echo則表示,通過回顯,在指令行中輸出hello,world!

第四步:通過:q退出檔案編輯模式後,使用sh hello.awk執行檔案

[root@ibm mwq]# sh hello.awk

hello,world!

好了,以上簡單學習的步驟就結束了。

以後有空閑時間一步步學習。。。。。

繼續閱讀