Posts

Showing posts with the label Shell

Shell Grammer

语言分类:编译语言,解释语言,汇编语言 编译语言: C / C++ / JAVA 强类型: 使用前必须声明变量类型 过程:源程序-->编译 -->链接 -->执行 基本变量类型:字符、整数、浮点数 解释语言: BASH / PERL / PYTHON / PHP / ruby 弱类型:直接使用变量 过程:源程序-->执行 默认变量类型:字符 "":弱引用 变量替换 ‘’:强引用 不做变量替换 `:命令替换 声明变量:declare 语法:declare <类型> <变量名> 类型:-i 整数 、-r 只读变量、-x 环境变量、 -a 数组 释放变量: unset 语法:unset <变量名> 只读变量(常量):readonly 语法:readonly <变量名> 默认环境变量都是大写,自定义变量尽量小写或者首字母大写 config file sequence Login shell: 1. /etc/profile 2. ~/.bash_profile 3. ~/.bashrc 4. /etc/bashrc Last run file is ~/.bash_profile Normal shell: 1. ~/.bashrc 2. /etc/bashrc PS1 提示符 \W: relative path \w: absolute path \h: hostname \u: username \t: 24 hour \T: 12 hour Default PS1="[\u@\h \W] \\$" Exampe: PS1="\u \h \w \t \\$" 系统变量: /etc/profile, ~/.bash_profile:  会话时读取一次 /etc/bashrc, ~/bashrc:  每次打开终端读取 /etc/profile.d:为不同版本shell特殊用法说明 用户变量 .bash_profile:  会话时读取一次 .ba...

Shell Learning

Image
echo echo '<context>' : no need to worry about the special character echo "<context>": need to worry about the special character. need add "\" before it But for variable you have to use " not ' Example: echo 'test $ test' --> test $ test echo "test $ test" --> test echo "test \$ test" --> test $ test #!/bin/bash fruit=apple count=5 echo "We have $count ${fruit}(s)" Result: We have 5 apple(s) echo "4 * 0.56"|bc --> 2.24 echo "scale=2;3/8"|bc --> .37 echo "scale=5;3/8"|bc --> .37500 echo "obase=2;ibase=10;100"|bc --> 110100 echo "obase=10;ibase=2;11100"|bc --> 28 echo "sqrt(100)"|bc --> 10 echo "10^2"|bc --> 100 stdin --> 0 stdout --> 1 stderr --> 2 stderr: change the error message output position cmd 2><file name> : the error me...