Linux操作系統(tǒng)Shell基礎(chǔ)知識(shí)
時(shí)間:
若木1由 分享
1 cat /etc/shells
查看計(jì)算機(jī)上可用的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 運(yùn)行firstscript
$ /bin/bash firstscript
如果找不到文件 使用pwd查看當(dāng)前目錄
$ /bin/bash pwd/firstscript
可見當(dāng)前運(yùn)行結(jié)果。
4 可以修改firstscript為執(zhí)行
$chmod a+x firstscript
此時(shí)輸入$ ./firstscript即可
上面的shell沒有jiao換,我們可以進(jìn)行jiao互,如下:
#!/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
同前面的運(yùn)行,自己測(cè)試。
查看計(jì)算機(jī)上可用的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 運(yùn)行firstscript
$ /bin/bash firstscript
如果找不到文件 使用pwd查看當(dāng)前目錄
$ /bin/bash pwd/firstscript
可見當(dāng)前運(yùn)行結(jié)果。
4 可以修改firstscript為執(zhí)行
$chmod a+x firstscript
此時(shí)輸入$ ./firstscript即可
上面的shell沒有jiao換,我們可以進(jìn)行jiao互,如下:
#!/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
同前面的運(yùn)行,自己測(cè)試。