猫宁!!!

参考链接:http://cn.linux.vbird.org/linux_basic/0340bashshell-scripts.php

鸟哥是为中国信息技术发展做出巨大贡献的人。

1-请创建一支 script ,当你运行该 script 的时候,该 script 可以显示: 1. 你目前的身份 (用 whoami ) 2. 你目前所在的目录 (用 pwd)

#!/bin/bash

echo -e "Your name is ==> $(whoami)"

echo -e "The current directory is ==> $(pwd)"

2-请自行创建一支程序,该程序可以用来计算『你还有几天可以过生日』啊?

#!/bin/bash

read -p "Pleas input your birthday (MMDD, ex> 0709): " bir

now=`date +%m%d`

if [ "$bir" == "$now" ]; then

echo "Happy Birthday to you!!!"

elif [ "$bir" -gt "$now" ]; then

year=`date +%Y`

total_d=$(($((`date --date="$year$bir" +%s`-`date +%s`))/60/60/24))

echo "Your birthday will be $total_d later"

else

year=$((`date +%Y`+1))

total_d=$(($((`date --date="$year$bir" +%s`-`date +%s`))/60/60/24))

echo "Your birthday will be $total_d later"

fi

3-让使用者输入一个数字,程序可以由 1+2+3... 一直累加到使用者输入的数字为止。

#!/bin/bash

read -p "Please input an integer number: " number

i=0

s=0

while [ "$i" != "$number" ]

do

i=$(($i+1))

s=$(($s+$i))

done

echo "the result of '1+2+3+...$number' is ==> $s"

4-撰写一支程序,他的作用是: 1.) 先查看一下 /root/test/logical 这个名称是否存在; 2.) 若不存在,则创建一个文件,使用 touch 来创建,创建完成后离开; 3.) 如果存在的话,判断该名称是否为文件,若为文件则将之删除后创建一个目录,档名为 logical ,之后离开; 4.) 如果存在的话,而且该名称为目录,则移除此目录!

#!/bin/bash

if [ ! -e logical ]; then

touch logical

echo "Just make a file logical"

exit 1

elif [ -e logical ] && [ -f logical ]; then

rm logical

mkdir logical

echo "remove file ==> logical"

echo "and make directory logical"

exit 1

elif [ -e logical ] && [ -d logical ]; then

rm -rf logical

echo "remove directory ==> logical"

exit 1

else

echo "Does here have anything?"

fi

5-我们知道 /etc/passwd 里面以 : 来分隔,第一栏为帐号名称。请写一只程序,可以将 /etc/passwd 的第一栏取出,而且每一栏都以一行字串『The 1 account is "root" 』来显示,那个 1 表示行数。

#!/bin/bash

accounts=`cat /etc/passwd | cut -d':' -f1`

for account in $accounts

do

declare -i i=$i+1

echo "The $i account is \"$account\" "

done

鸟哥私房菜基础篇:学习 Shell Scripts习题的更多相关文章

  1. 鸟哥私房菜基础篇:认识与学习BASH习题

    猫宁!!! 参考链接:http://linux.vbird.org/linux_basic/0320bash.php 鸟哥是为中国信息技术发展做出巨大贡献的人. 1-在 Linux 上可以找到哪些 s ...

  2. 鸟哥私房菜基础篇:vim 程序编辑器习题

    猫宁!!! 参考链接:http://cn.linux.vbird.org/linux_basic/0310vi.php 鸟哥是为中国信息技术发展做出巨大贡献的人. 1-我用 vi 开启某个档案后,要在 ...

  3. 鸟哥私房菜基础篇:Linux 磁碟与档案系统管理习题

    猫宁!!! 参考链接:http://linux.vbird.org/linux_basic/0230filesystem.php 鸟哥是为中国信息技术发展做出巨大贡献的人. 1-我们常常说,开机的时候 ...

  4. 鸟哥私房菜基础篇:Linux 的档案权限与目录配置习题

    猫宁!!! 参考链接:http://linux.vbird.org/linux_basic/0210filepermission.php 鸟哥是为中国信息技术发展做出巨大贡献的人. 1-早期的 Uni ...

  5. 鸟哥私房菜基础篇:Linux 档案与目录管理习题

    猫宁!!! 参考链接:http://linux.vbird.org/linux_basic/0220filemanager.php 鸟哥是为中国信息技术发展做出巨大贡献的人. 1-什么是绝对路径与相对 ...

  6. 鸟哥私房菜基础篇:Linux是什么习题

    猫宁!!! 参考链接:http://cn.linux.vbird.org/linux_basic/0110whatislinux.php#ex 鸟哥是为中国信息技术发展做出巨大贡献的人. 1-你在你的 ...

  7. 鸟哥私房菜基础篇:安裝 CentOS7.x习题

    猫宁!!! 参考链接:http://linux.vbird.org/linux_basic/0157installcentos7.php 鸟哥是为中国信息技术发展做出巨大贡献的人. 1-Linux的目 ...

  8. 鸟哥私房菜基础篇:Linux 账号管理与 ACL 权限配置习题

    猫宁!!! 参考:http://cn.linux.vbird.org/linux_basic/0410accountmanager.php 1-root 的 UID 与 GID 是多少?而基于这个理由 ...

  9. 鸟哥私房菜基础篇:程序管理与 SELinux 初探习题

    猫宁!!! 参考:http://cn.linux.vbird.org/linux_basic/0440processcontrol.php 1-简单说明什么是程序 (program) 而什么是程序 ( ...

随机推荐

  1. 1 npoi 网上 不用模板 设置密码 workbook.WriteProtectWorkbook("password", "admin"); 、、 2 locked.IsLocked = true; sheet1.ProtectSheet("password");NPOI操作EXCEL--设置密码才可以修改单元格内容 3 模板设置密码 确定原密码 设置新密码

    1 workbook.WriteProtectWorkbook("password", "admin"); 还是可以进去 只读进去 可以编辑 编辑就另存为   ...

  2. LeetCode232 Implement Queue using Stacks Java 题解

    题目: Implement the following operations of a queue using stacks. push(x) -- Push element x to the bac ...

  3. Sharepoint2013 列表的NewForm 页面加入一个 保存新建 button

    昨天一同事问我怎样在sharepoint2013的NewForm.aspx页面上加入一个 save and new的button.实现save 和new的功能.save的功能和默认的save按钮效果一 ...

  4. 一个简单的EBNF范式的实现

    最近无事在看书的时候发现了这个东西刹那间突然觉得大学时候编译原理书上的的什么语法分析书.上下文无关等晦涩难懂的概念清晰了许多今天把它贴出来希望也能让你回想起些往事... 至于EBNF范式是什么东西,网 ...

  5. jquery一个比较好的轮播图jQuery.kinMaxShow介绍

    kinMaxShow API 可选参数以及详解 kinMaxShow 主参数详解 参数名称 默认值 简单释义 height 500 [整型 (单位:像素)]焦点图高度,必须设置 缺省则启用默认高度 5 ...

  6. storage engine option for directoryPerDB

    Requested option conflicts with current storage engine option for directoryPerDB; you requested true ...

  7. mongo 原理 Replica Set Oplog

    [客户的写请求全部发送至主节点] Primary. The primary receives all write operations. Secondaries. Secondaries replic ...

  8. js 时间戳精确值的问题

    最近做一个多图上传的功能,通过name + 时间戳命名,结果发现时间戳竟然一样,一直以为是代码逻辑的问题,结果出错在时间戳的获取上了. 关于时间戳的获取方式: 1.Date.parse() var d ...

  9. android user用户版本提高adb权限【转】

    本文转载自:http://blog.csdn.net/liyongming1982/article/details/14108111 有的user用户版本的log 不全,且push/pull某些文件或 ...

  10. POJ3087 Shuffle'm Up —— 打表找规律 / map判重

    题目链接:http://poj.org/problem?id=3087 Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...