cat /etc/shells
命名 firstscript,內容:
#! /bin/bash
# This is a test.
echo -n Your current directory is:
pwd
echo $HOME
echo Your current directory is:
pwd
# END.
/bin/bash firstscript
找不到檔案時用:/bin/bash $(pwd)/firstscript
chmod a+x firstscript
之後可直接 ./firstscript 執行。
讀取使用者輸入並條件判斷:
#!/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
自行在終端機輸入執行體驗互動效果。