Linux的shell script

//编辑shell:
vi a.sh
//子进程运行shell
sh a.sh
//主线程运行shell
source a.sh
相关例子:
#!/bin/bash
echo "hello linux!"
#!/bin/bash
echo "我要创建三个文件"
read -p "请输入文件名:" fileuser
#防止任意输入 分析文件名是否输入为空
filename=${fileuser:-"filename"} #开始判断是否配置文件名
#开始利用date命令来取得所需要的文件名 date1=$(date --date='2 days ago' +%Y%m%d) #前两天
date2=$(date --date='1 days ago' +%Y%m%d) #前yi
date3=$(date +%Y%m%d) #配置文件名
file1=${filename}${date1}
file2=${filename}${date2}
file3=${filename}${date3} touch "$file1"
touch "$file2"
touch "$file3"
#/bin/bash

echo -e "请输入2个数字相乘"
read -p "第一个数:" a
read -p "第二个数:" b
echo -e "两个数的乘积:$(($a*$b))"
#/bin/bash
echo -e "文件判断"
read -p "请输入文件名:" filename
test -z $filename && echo "你需要输入文件名" && exit 0
test ! -e $filename && "文件名为:$filename的文件不存在" && exit 0
#开始判断文件类型与属性
test -f $filename && filetype="正常文件"
test -d $filename && filetype="正常文件夹"
test -r $filename && perm="可读"
test -w $filename && perm="$perm 可写"
test -x $filename && perm="$perm 可执行"
#开始输出信息
echo "文件:$filename 是 $filetype"
echo "权限:$perm"
#/bin/bash
read -p "请输入(Y/N): " yn
[ "$yn" == "Y" -o "$yn" == "y" ] && echo "好的 继续" && exit 0 //[]里面的运算表达式 注意加空格
[ "$yn" == "N" -o "$yn" == "n" ] && echo "否" && exit 0
echo "我看不懂你输入的命令"
#!/bin/bash
read -p "input:" a
case "$a" in
"1")
echo "input 1"
;;
"2")
echo "input 2"
;;
*)
echo "*"
;;
esac
#!/bin/bash
#获取账号名称
for username in dog cat elephont
do
echo "$username"
done
#!/bin/bash
for((i=1;i<=10;i++))
do
echo "$i"
done
#!/bin/bash
while [ "$yn" != "yes" -a "$yn" != "YES" ]
do
read -p "请输入yes:" yn
done
echo "输入正确了"

Linux的shell script的更多相关文章

  1. “windows的批处理”与“Linux的shell script”的类比学习

    从2005年开始,做了将近10年的系统维护,先是做网络接入管理,然后做网络安全与审计,然后做服务器管理等整个网络系统的运营管理:现在又兼着做一些Linux下的视频监控系统的软硬件维护.过程中遇到太多重 ...

  2. linux中shell script的追踪与调试

    Shell调试篇 sh [-nvx] scripts.sh -n:不要执行script,仅查询语法的问题: -v:在执行script前,先将script的内容输出到屏幕上: -x:将使用到的scrip ...

  3. 一起来学linux:shell script(一)关于变量

    p { margin-bottom: 0.25cm; line-height: 120% } (一)首先来看什么是变量,在shell中打印出变量采用的是echo $path或者echo ${path} ...

  4. 一起来学linux:shell script(二)关于脚本

    (一)首先来看shell脚本的执行方式,shell脚本的后缀名都是sh文件. 1 sh test.sh 2 source test.sh 这两种方式有什么区别呢.test.sh 里的脚本很简单, 从键 ...

  5. 调用远程linux服务器shell脚本

    package com.haiyisoft.hyoaPc.ui; import java.io.BufferedReader;import java.io.IOException;import jav ...

  6. (copy) Shell Script to Check Linux System Health

    source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...

  7. Shell script for logging cpu and memory usage of a Linux process

    Shell script for logging cpu and memory usage of a Linux process http://www.unix.com/shell-programmi ...

  8. linux基础之Shell Script入门介绍

    本文介绍下,学习shell script编程的入门知识,通过几个入门实例,带领大家走进shell script的神圣殿堂,呵呵,有需要的朋友参考下. 本文转自:http://www.jbxue.com ...

  9. Linux基础之-shell script(变量,运算符,流程控制,函数)

    一.shell script Shell 脚本(shell script),是一种为shell编写的脚本程序.业界所说的shell通常都是指shell脚本,但读者朋友要知道,shell和shell s ...

随机推荐

  1. 怎样使用word2013发布csdn博客

    目前大部分的博客作者在用Word写博客这件事情上都会遇到以下3个痛点: 1.所有博客平台关闭了文档发布接口,用户无法使用Word,Windows Live Writer等工具来发布博客.使用Word写 ...

  2. dlib安装教程(for linux)

    https://blog.csdn.net/LoHiauFung/article/details/78454905 https://www.linuxidc.com/Linux/2017-11/148 ...

  3. (网络流 模板)A Plug for UNIX -- poj -- 1087

    链接: http://poj.org/problem?id=1087 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82835#probl ...

  4. hdu 5038 求出现次数最多的grade

    http://acm.hdu.edu.cn/showproblem.php?pid=5038 模拟水题 求出现次数最多的grade.如果有多个grade出现的次数一样多,且还有其他的grade,则把这 ...

  5. 动态的把固定格式的json数据以菜单形式插入

    var root=$("#side-menu"); $(menuData).each(function(i,n){ var top1Li=$("<li>< ...

  6. 谷类 cereal

  7. 【转】【译】【Win10】在你的程序标题栏中显示后退按钮

    原文地址:http://www.sharpgis.net/post/2015/05/21/Displaying-a-backbutton-in-your-app-window 免责声明:这篇文章基于 ...

  8. git archive命令详解

    git archive可以将加了tag的某个版本打包提取出来,例如: git archive -v --format= > v0..zip --format表示打包的格式,如zip,-v表示对应 ...

  9. musql 添加字段语句

    修改表tax_version添加up_content属性为text类型非空,注释为“更新内容”,字段添加再“name”属性后面 ALTER TABLE `tax_version` ADD `up_co ...

  10. SSRS (一)创建基础报表

    ReportService创建基础报表 1.数据库SQL Server2012选择SQL Server Data Tools 2.创建商业智能(BI)项目 选择报表服务器项目 ReportServic ...