歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Linux操作系統Shell基礎知識

Linux操作系統Shell基礎知識

日期:2017/3/2 16:51:56   编辑:SHELL編程

◆Shell基礎知識

1、cat /etc/shells

查看計算機上可用的shell

2、編寫shell,保存為firstscript

#! /bin/bash

# This is a test.

echo -n Your current directory is:

pwd

echo $HOME

echo Your current directory is:

pwd

#END.


3、運行firstscript

$ /bin/bash firstscript

如果找不到文件 使用pwd查看當前目錄

$ /bin/bash pwd/firstscript

可見當前運行結果。

4、可以修改firstscript為執行

$chmod a+x firstscript

此時輸入$ ./firstscript即可

上面的shell沒有交換,我們可以進行交互,如下:

#!/bin/sh

echo -n Please input your ID:

read id_var

echo -n Please input your password:

read password

echo User ID = $id_var

echo password = $password

if [ $password = "admin" ]; then

echo "password is right"

else

echo "password is wrong"

fi


同前面的運行,自己測試。

◆命令行中“\”和“--”符號所代表的含義

\ 如果在行末,是說明本行還未結束,下面一行和本行是一起的意思.

-- 就是選項的開始,一般一個字母的選項用 - 開頭,多個字母的就用 -- 開頭.

“\”後如果是回車,不換行的話可能省略;但要是其它字符,就不能省略。

“\”告訴系統後面跟著的字符為原意,不是命令。

比如有個文件名中帶有空格,就要在空格前加一個“\”。

Copyright © Linux教程網 All Rights Reserved