当前位置: 首页 > news >正文

C高级--day3(shell中的输入、命令置换符、数组、算数运算、分支结构)

 

#!/bin/bash
p=`ls ~/ -l | grep "^-" | wc -l`
q=`ls ~/ -l | grep "^d" | wc -l`
echo "普通文件个数:$p"
echo "目录文件个数:$q"

#!/bin/bash
read file
pos=`expr index $file \.`
str=`expr substr $file $((pos+1)) 2`
if [ $str == "sh" ]
thenif [ -x $file ]then echo "$file是脚本文件"bash $fileelsechmod u+x $filefi
elseecho "$file不是脚本文件"
fi

 

#!/bin/bash
read file1 file2
if [ $file1 -nt $file2 ]
thenecho "file1比file2更新"
elif [ $file1 -ot $file2 ]
then  echo "file2比file1更新"
fi

#!/bin/bash
read user
name=`grep -q $user /etc/passwd`
if [ $? -eq 0 ]
thenecho "$user用户存在"
elseecho "$user用户不存在"sudo adduser $user
fi

  

 

#!/bin/bash
read score
if [ $score -gt 90 -a $score -le 100 ]
thenecho "A等级"
elif [ $score -gt 80 -a $score -le 90 ]
then echo "B等级"
elif [ $score -gt 70 -a $score -le 80 ]
then echo "C等级"
elif [ $score -gt 60 -a $score -le 70 ]
then echo "D等级"
elif [ $score -gt 0 -a $score -le 60 ]
then echo "不合格"
elseecho "输入的成绩不合法,请重新输入"
fi

 

#!/bin/bash
name=`whoami`
arr=( $name `id -u $name` `echo $PATH`)
echo ${arr[*]}

 

 

#!/bin/bash
num=`ls -d /etc/[Pp]* | wc -l`
echo $num

 

http://www.lryc.cn/news/109343.html

相关文章:

  • 安防监控国标GB28181平台EasyGBS视频快照无法显示是什么原因?如何解决?
  • route命令 路由表 Linux Centos
  • CMMI评审
  • 深入了解 PostgreSQL 扩展插件
  • 记一次kernel patch(附开源贡献相关)
  • Pytorch Tutorial【Chapter 1. Basic operation of tensor】
  • [环境配置]centos7安装vncserver
  • Excel功能总结
  • 用Rust实现23种设计模式之 组合模式
  • opencv36-形态学操作-膨胀 cv2.dilate()
  • 8266 ESP-07模块的使用 以及详细介绍
  • Linux之 centos、Ubuntu 安装常见程序 (-) Mysql 5.7 版本和8.0版本
  • 【IDEA+Spark Streaming 3.4.1+Dstream监控套接字流统计WordCount保存至MySQL8】
  • Dcat Admin 入门应用指南
  • 计算机视觉:替换万物Inpaint Anything
  • AWS——01篇(AWS入门 以及 AWS之EC2实例及简单实用)
  • Clickhouse 优势与部署
  • 全球数据泄露事件增加近三倍
  • 【雕爷学编程】 MicroPython动手做(38)——控制触摸屏2
  • 钉钉微应用
  • 【 SpringSecurity】第三方认证方法级别安全
  • 达梦数据库在windows上的安装
  • 新手Vite打包工具的使用并解决yarn create vite报错
  • SpringMVC框架——First Day
  • 基于C++雪花算法工具类Snowflake -来自chatGPT
  • 若依打印sql
  • Camunda BPM Run下载(7.20)
  • 【Ubuntu】Ubuntu 22.04 升级 OpenSSH 9.3p2 修复CVE-2023-38408
  • 【知网检索】2023年金融,贸易和商业管理国际学术会议(FTBM2023)
  • 数据可视化:Matplotlib详解及实战