Linux下shell入门

1,第一个helloworld shell程序
  vi helloworld.sh
 #!/bin/bash  #指定了shell的版本,魔术行
 #这是一个示例文件
echo "helloworld!"
回到控制台:
 chmod u+x helloworld.sh;    #修改为可执行文件
./ helloworld.sh             #执行程序
 
2, 加入变量:vi var.sh;
     log="monday"

     echo "The value of logfile is"
     echo "logout is ${log} out"

     echo $log
    
    输出 ”The value of logfile is
  logout is monday out
          monday"

3  ``中的内容将会被执行,并且返回结果作为这个的表达式的值。
    vi quote。sh
    #!/bin/bash
    log=saturday
    echo "Today is $log"
    echo 'Today is $log'
    echo "Today is `date`"
    
     输出: Today is saturday
            Today is $log
     Today is 2011年。。。。

4 shell中的执行命令和控制命令
 #!/bin/bash

 echo "Enter password"
 read password    #读入一个变量
 if["$password"="mypassword"];
 then
  echo "welcome"
 fi


 #!/bin/bash
  sum=0
  number=1
  while test $number -le 100 # -le 小于等于 test是测试命令
  do
 sum=$[ $sum + $number ]
 let number=$number+1
  done
  echo "The summary is $sum"

猜你喜欢

转载自windking88.iteye.com/blog/973719