linux bash学习

Posted 92#

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux bash学习相关的知识,希望对你有一定的参考价值。

 

1.请你以 read 指令的用途,撰写一个 script ,他可以让使用者输入:1. first name 与 2. last name, 最后并且在屏幕上显示:“Your full name is: ”的内容:

#!/bin/bash
#Program:
#       use input his first name and last name.Program shows his full name.
#History:
#2017/07/27     lzyer   release
read -p "Please input your first name:" firstname
read -p "Please input your last name:" lastname
echo "Your full name is : ${firstname}.${lastname}"

2.随日期变化:利用 date 进行文件的创建

#!/bin/bash
#Program:
#       Program creates three files, which named by user\'s input and date command.
#History
#2017/07/28     lzyer  First release

echo "I will use \'touch\' command to create 3 file."
read -p "Please input your filename :" fileuser
filename=${fileuser:-"filename"}
date1=$(date --date=\'2 days ago\' +%Y%m%d)
date2=$(date --date=\'1 days ago\' +%Y%m%d)
date3=$(date +%Y%m%d)
file1=${filename}${date1}
file2=${filename}${date2}
file3=${filename}${date3}

touch "${file1}" "${file2}" "${file3}"

3.数值运算:简单的加减乘除

#!/bin/bash
#Program:
#       use input 2 integer numbers; program will cross these two numbers.
#History:
#2017/07/28     lzyer First release
echo "you should input 2 numbers, i will multipfying them !"
read -p "first numbe: " firstnumber
read -p "second number: " secondnumber
total=$((${firstnumber}*${secondnumber}))
echo "The result of ${firstnumber} x ${secondnumber} ==> ${total}"

4.sh和source的差异性

以上是关于linux bash学习的主要内容,如果未能解决你的问题,请参考以下文章

Linux bash基础特性二

谢烟客---------Linux之bash脚本编程---if补充和for循环

linux学习19 shell脚本基础-bash脚本编程基础及配置文件

Linux学习笔记:bash颜色显示及shell脚本相关

[Linux Shell学习系列七]Bash循环——1for循环

零基础学习云计算及大数据DBA集群架构师Linux Bash Shell编程及系统自动化2015年1月13日周三