Linux · 2009-01-12

shell编程入门_pwd命令列出当前目录

最近下定决心,一定要掌握基本的shell,在linux下哪有不会shell的?(我看估计很少,很不行,我就是其中一个 -_-!!! )
刚开始的话,太难的一时半会儿肯定也啃不下去,在应用中掌握嘛(个人看法~)我觉得很多论坛都是很好的学习地方!
原则就是多看,多思考,多动手,多搜索,多问!只要掌握这五个”多”,相信一段日子后我们也会成为帮助别人的人~
今天入门写了个简单得不能再简单的shell程序,其作用判断当前的路径,也就是linux下的pwd命令。其实别看很简单,知识就是一点一滴这样掌握下来的,没有人天生就会干什么~

#!/bin/sh
a=$(pwd)
if [ “$a” = “/root” ]
then
echo “you are in the root directory”
else
echo “you are in the “$a” directory”
fi



root@debian:~# ./test/where.sh #在root路径运行
you are in the root directory

root@debian:~/test# ./where.sh #在/root/test路径下运行
you are in the /root/test directory