变量

系统自带变量

echo $PATH $HOME $PWD

自定义变量

# a=
# echo $a
1
# b=
# echo $b
2

写与用户交互的脚本

vim .sh
#!/bin/bash
##
##
read -p "please input a number: " number
echo $number
sh .sh

please input a number:123456

123456 (输入什么,反馈什么)

超时自动退出,-t跟时间。超出5秒自动退出

read  -p "please input a number: " number
echo $number
改为
read -t -p "please input a number: " number
echo $number

内置变量 $0 $1 $2 $3

vim .sh
#!/bin/bash
##
##
echo "\$0=$0"
echo "\$1=$1"
echo "\$2=$2"
echo "\$3=$3"
sh .sh

$0=3.sh
$1=
$2=
$3=

 sh .sh aa bb cc

$0=3.sh
$1=aa
$2=bb
$3=cc

sh .sh aa bb

$0=3.sh
$1=aa
$2=bb
$3=

$0表示文件名

$1$2$3分别表示第一个二个三个参数

进行数学运算

# a=;b=
# c=$[$a+$b]
# echo $c

Shell编程进阶 1.4 shell自定义变量的更多相关文章

  1. Shell编程进阶 2.0 shell中断继续退出

    break    continue   exit break 结束本次for循环 写个for循环脚本 vim for2.sh #!/bin/bash ## 5` do echo $i ] then b ...

  2. Shell编程进阶 1.2 shell结构及执行

    创建一个shell脚本 mkdir shell vim first.sh #!/bin/bash ##The first test shell script. ##Written by wangsha ...

  3. Shell编程进阶 2.1 shell函数

    函数 vim fun.sh #!/bin/bash function mysum() { sum=$[$+$] echo $sum } a= b= mysum $a $b sh fun.sh 6 可以 ...

  4. Shell编程进阶 2.2 shell数组

    给一个字符指定一个数组 怎么显示数组 a= echo $a a=( ) echo $a echo ${a[@]} echo ${a[*]} 指定显示数组中第几个数字 echo ${a[]} echo ...

  5. 【转】Shell编程进阶篇(完结)

    [转]Shell编程进阶篇(完结) 1.1 for循环语句 在计算机科学中,for循环(英语:for loop)是一种编程语言的迭代陈述,能够让程式码反复的执行. 它跟其他的循环,如while循环,最 ...

  6. shell编程系列1--shell脚本中的变量替换

    shell编程系列1--shell脚本中的变量替换 变量替换总结: .${变量#匹配规则} # 从头开始匹配,最短删除 .${变量##匹配规则} # 从头开始匹配,最长删除(贪婪模式) .${变量%匹 ...

  7. 【shell编程基础1】shell变量篇

    Bash shell bash shell 是bourne shell 的升级版,“bourne again shell”.ubuntu的默认shell. 预备知识 1. "#!" ...

  8. linux shell编程进阶学习(转)

    第一节:基础 ls -lh  ——可以用户友好的方式看到文件大小 file 文件名 ——查看文件类型 stat 文件名 ——查看文件当前状态 man 命令/函数名 ——查看详细的帮助文档 man中看某 ...

  9. Shell编程进阶篇(完结)

    1.1 for循环语句 在计算机科学中,for循环(英语:for loop)是一种编程语言的迭代陈述,能够让程式码反复的执行. 它跟其他的循环,如while循环,最大的不同,是它拥有一个循环计数器,或 ...

随机推荐

  1. Codeforces Round #374 (Div. 2) A , B , C 水,水,拓扑dp

    A. One-dimensional Japanese Crossword time limit per test 1 second memory limit per test 256 megabyt ...

  2. ANT+JMETER集成3 (添加邮件附件)

    在build.xml文件<email>中加入下面几行代码 <fileset dir="C:\apache-jmeter-3.0\html/"> <in ...

  3. 解决:TypeError: 'list' object is not callable

    如果list变量和list函数重名,会有什么后果呢?我们可以参考如下代码: list = ['泡芙', '汤圆', '鱼儿', '骆驼'] tup_1 = (1, 2, 3, 4, 5) tupToL ...

  4. 51nod 1128 二分

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1128 1128 正整数分组 V2 基准时间限制:1 秒 空间限制:131 ...

  5. 【51Nod】-1326 遥远的旅途

    Description 一个国家有 N 个城市, 这些城市被标为 0,1,2,...N-1. 这些城市间连有 M 条道路, 每条 道路连接两个不同的城市, 且道路都是双向的. 一个小鹿喜欢在城市间沿着 ...

  6. oracle管理优化必备语句以及oracle SQL语句性能调整

    本文转自http://www.dataguru.cn/article-3302-1.html oracle数据库管理优化必备语句: 1. SELECT T.START_TIME,T.USED_UBLK ...

  7. 浅谈Vue个性化dashBoard 布局

    dashBoard布局在管理系统使用比较多:使用自己喜欢的方式进行自定义布局 使用npm 安装 npm install vue-grid-layout 全局使用 import vueGridLayou ...

  8. 烂泥Linux学习笔记

    把最近学习过程中所写的文章整理了下:注意:本帖会持续性更新!!! 虚拟化篇:<烂泥:虚拟化KVM安装与配置><烂泥:KVM安装centos6.5系统><烂泥:KVM中安装 ...

  9. CodeForces - 803F: Coprime Subsequences(莫比乌斯&容斥)

    Let's call a non-empty sequence of positive integers a1, a2... ak coprime if the greatest common div ...

  10. django的get_or_create

    转:http://www.nanerbang.com/article/51/ get_or_create会根据条件从数据库里面查找符合条件的记录,如果没有符合条件的记录,则新创建一条记录