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

新手學堂:Linux操作系統Shell基礎知識

日期:2017/3/2 16:51:53   编辑: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