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"

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值