标签:etc 根据 英文字母 条件 编程 引号 选项 后缀 bash

[oracle@oracle ~]$ echo $SHELL/bin/bash[oracle@oracle ~]$
Shell脚本编程  | |||
Shell基础 变量的使用 算术运算、数组应用 排序、提取、组合命令  | 条件测试 if语句、for循环、while循环、case分支和函数应用  | 正则表达式 expect dialog  | sed Awk 案例  | 
第1-2章  | 第3-4章  | 第5-6章  | 第7-8章  | 

[root@oracle ~]# cat /etc/shells/bin/sh ---》最小化安装都有/bin/bash ---》推荐使用/sbin/nologin/bin/dash/bin/tcsh/bin/csh/bin/ksh[root@oracle ~]#

env 查看环境变量set 查看当前用户可以使用的所有的变量
[root@oracle ~]# history1 cd /etc2 ls3 cd sysconfig4 ls5 cd network-scripts6 ls
[root@oracle ~]# !2lsanaconda-ks.cfg Documents install.log Music Public tmpDesktop Downloads install.log.syslog Pictures Templates Videos[root@oracle ~]# !cdcd /backup[root@oracle backup]#
[root@oracle ~]# vi /etc/profile# /etc/profile# System wide environment and startup programs, for login setup# Functions and aliases go in /etc/bashrcHISTSIZE=1000
[root@oracle ~]# aliasalias cp=‘cp -i‘alias l.=‘ls -d .* --color=auto‘alias ll=‘ls -l --color=auto‘alias ls=‘ls --color=auto‘alias mv=‘mv -i‘alias rm=‘rm -i‘alias which=‘alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde‘[root@oracle ~]#
[root@localhost ~]# vi first.shcd /boot/pwdls -lh vml*
[root@localhost ~]# chmod +x first.sh[root@localhost ~]# ls -l first.sh-rwxr-xr-x 1 root root 144 04-26 15:02 first.sh

====声明:以#!开头注释:以#开头#!/bin/bash ---》申明使用bash作为默认shell来执行脚本##########################################Function: auto fdisk#Usage: bash auto_fdisk.sh#Author: Customer service department#Company: Alibaba Cloud Computing#Version: 2.0#########################################===========
lftp 172.16.1.1:~> ls-rwxr-xr-x 1 0 0 17921378 Sep 09 18:19 PotPlayer视频播放器.zipdrwxr-xr-x 8 0 0 4096 Nov 20 19:10 linux-videodrwxr-xr-x 2 0 0 4096 Feb 29 13:46 mysqldrwxr-xr-x 4 0 0 4096 Sep 12 20:42 pythondrwxr-xr-x 7 0 0 4096 Mar 04 16:16 softwaredrwxr-xr-x 4 0 0 4096 Jan 23 15:10 teacher_fengdrwxr-xr-x 7 0 0 4096 Jan 05 13:44 videodrwxr-xr-x 2 0 0 4096 Dec 13 22:56 xianglftp 172.16.1.1:/> cd teacher_feng/lftp 172.16.1.1:/teacher_feng> lsdrwxr-xr-x 10 0 0 4096 Dec 21 15:16 9_classdrwxr-xr-x 10 0 0 4096 Mar 05 14:05 califeng-rw-r--r-- 1 0 0 13990 Oct 31 23:56 mysql_plan.xlsxlftp 172.16.1.1:/teacher_feng> cd 9_class/linux-shell-course/lftp 172.16.1.1:/teacher_feng/9_class/linux-shell-course> get yuli_admin_system_user-v2.sh6886 bytes transferredlftp 172.16.1.1:/teacher_feng/9_class/linux-shell-course>[root@chinaitsoft lianxi]# lftp 172.16.1.1lftp 172.16.1.1:~> bye[root@chinaitsoft lianxi]# lftp 172.16.1.1lftp 172.16.1.1:~> exit[root@chinaitsoft lianxi]# lftp 172.16.1.1lftp 172.16.1.1:~> quit[root@chinaitsoft lianxi]#====get是下载文件mirror 下载文件夹退出 quit bye exit默认情况下下载的文件或者文件夹存放在当前目录lftp 172.16.1.1:/> !ls 在本机上执行ls命令aa frist.sh sed yuli_admin_system_user-v2.shlftp 172.16.1.1:/>lftp 172.16.1.1:/> !pwd/lianxilftp 172.16.1.1:/> lcd /root 切换本地路径 locallcd 成功, 本地目录=/rootlftp 172.16.1.1:/>====
[root@oracle ~]# day=sunday[root@oracle ~]# echo $daysunday[root@oracle ~]# DAY=sun[root@oracle ~]# echo $daysunday[root@oracle ~]# echo $DAYsun[root@oracle ~]#
[root@oracle ~]# name="hai lian tian"[root@oracle ~]# echo $namehai lian tian[root@oracle ~]#
[root@oracle ~]# DAY=Sunday[root@oracle ~]# echo "Today is Sunday" >$DAY_file.txt[root@oracle ~]# ls -a.txt[root@oracle tmp]# echo "today is sunday " >${DAY}_file.txt[root@oracle tmp]# ls -a. .. .esd-0 .ICE-unix Sunday_file.txt .X0-lock .X11-unix[root@oracle tmp]#
var2=$(rpm -qf $(which fdisk))[root@oracle tmp]# var2=$(rpm -qf $(which fdisk))[root@oracle tmp]# echo $var2util-linux-ng-2.17.2-12.14.el6.x86_64[root@oracle tmp]#
[root@oracle tmp]# name="hello"[root@oracle tmp]# myname0=‘My name is $name‘[root@oracle tmp]# myname1="My name is ‘$name‘"[root@oracle tmp]# myname2=‘My name is "$name"‘[root@oracle tmp]# myname3="My name is "$name""[root@oracle tmp]# myname4=‘My name is ‘$name‘‘[root@oracle tmp]# echo $myname0My name is $name[root@oracle tmp]# echo $myname1My name is ‘hello‘[root@oracle tmp]# echo $myname2My name is "$name"[root@oracle tmp]# echo $myname3My name is hello[root@oracle tmp]# echo $myname4My name is hello[root@oracle tmp]#
| 符号 | 意义 | 
| \n | 新的一行 | 
| \t | 表示tab键 | 
[root@oracle ~]# echo -e "\tabc123"abc123[root@oracle ~]# echo -e "\tabc\n123"abc123[root@oracle ~]#
[root@oracle tmp]# cat read.sh#!/bin/bash###############################Function: read using#Us#Author: wangyu#Company: haitianjingyu#Version: 1.0##############################read -p "please input you name:" nameread -n3 -s -p "input password:" pwdecho -e "\n you username is $name ,password is $pwd"[root@oracle tmp]# bash read.shplease input you name:haiinput password:you username is hai ,password is hai[root@oracle tmp]#

#!/bin/bash###############################Function: menu#Author: wangyu#Company: haitianjingyu#Version: 1.0##############################clearecho -e "\n\t\t\t***system menager tool***"echo -e "\n\t1.\tshow disk space info"echo -e "\t2.\tshow network connector info"echo -e "\t3.\tshow memory using info"echo -e "\t0.\texit menu"echo -en "\n\t\tinput option:"read -n1 numecho -e "\nyou option is $num"


[root@oracle tmp]# cat adduser.sh#!/bin/bash###########################Function: create new user#Author: wangyu#Company: haitianjingyu#Version: 1.0##########################read -p "add new user:" nameread -s -p "user $name password:" pwduseradd $nameecho $pass|passwd --stdin $name &>/dev/nullecho -e "\nuser $name is ok"[root@oracle tmp]# bash adduser.shadd new user:hai2user hai2 password:user hai2 is ok[root@oracle tmp]#






#!/bin/bash
read -p "请输入查找的文件夹: " DIR
for i in "$@"
do
if(i!=0){
NUM=$(find $DIR -type f -name "*$i" | wc -l)
echo "以$i结尾的文件的数目是: " $NUM
}
fi
done
read -p "请输入一个挂载点的目录绝对路径:" DIR
mkdir -p $DIR
umount /dev/sr0 &> /dev/null
mount /dev/sr0 $DIR &> /dev/null
(cd /etc/yum.repos.d; tar *.repo *repo.tar &> /dev/null)
cat << EOF > /etc/yum.repos.d/yumlocal.repo
[Server]
name=Server
baseurl=file:///$DIR
enabled=1
gpgcheck=0
EOF
yum clean all &> /dev/null && echo yum is ok


标签:etc 根据 英文字母 条件 编程 引号 选项 后缀 bash
原文地址:http://www.cnblogs.com/haitianjingyu/p/6973709.html