http://www.gnu.org/software/bash/

http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/

[root@250-shiyan ~]# rpm -qa|grep bash
bash-4.1.2-15.el6_4.x86_64
type-.-source-let-(())-history-declare

[root@-shiyan prog]# help type
type: type [-afptP] name [name ...]
Display information about command type. For each NAME, indicate how it would be interpreted if used as a
command name. Options:
-a display all locations containing an executable named NAME;
includes aliases, builtins, and functions, if and only if
the `-p' option is not also used
-f suppress shell function lookup
-P force a PATH search for each NAME, even if it is an alias,
builtin, or function, and returns the name of the disk file
that would be executed
-p returns either the name of the disk file that would be executed,
or nothing if `type -t NAME' would not return `file'.
####要么返回可能被执行的磁盘文件名,要么假如type -t NAME不返回file则什么也不做。
-t output a single word which is one of `alias', `keyword',
`function', `builtin', `file' or `', if NAME is an alias, shell
reserved word, shell function, shell builtin, disk file, or not
found, respectively
####如果NAME是一个别名,shell保留字,shell函数,shell内部命令,磁盘file,或者没找到,那么分别对应输出alias,keyword,function,builtin,file,或者空的其中一个单词。
Arguments:
NAME Command name to be interpreted.
####被解读的命令名
Exit Status:
Returns success if all of the NAMEs are found; fails if any are not found.
####假如所有的NAMEs都找到返回成功;假如任何一个未找到就返回失败。
typeset: typeset [-aAfFilrtux] [-p] name[=value] ...
Set variable values and attributes. Obsolete. See `help declare'. [root@-shiyan prog]# type -a fdisk for cd
fdisk is /sbin/fdisk
for is a shell keyword
cd is a shell builtin
[root@-shiyan prog]# type -t fdisk for cd ls __udisks
file
keyword
builtin
alias
function
[root@-shiyan prog]# type -p dir fdisk
/usr/bin/dir
/sbin/fdisk
[root@250-shiyan prog]# declare -f|more  先查看函数名,再查看类型
[root@250-shiyan prog]# type __udisks
__udisks is a function [root@250-shiyan frag]# type -a : [[ {
: is a shell builtin
[[ is a shell keyword
{ is a shell keyword
[root@250-shiyan frag]# type -a [
[ is a shell builtin
[ is /usr/bin/[
[root@-shiyan frag]# help :
:: :
Null command. No effect; the command does nothing. Exit Status:
Always succeeds. http://blog.csdn.net/ysdaniel/article/details/7905818 Shell中[和[[的异同
[root@-shiyan frag]# help [
[: [ arg... ]
Evaluate conditional expression. This is a synonym for the "test" builtin, but the last argument must
be a literal `]', to match the opening `['.
####是内置test的同义词,但最后一个参数必须是一个字符],来匹配开始的[
[[ ... ]]: [[ expression ]]
Execute conditional command. Returns a status of or depending on the evaluation of the conditional
expression EXPRESSION. Expressions are composed of the same primaries used
by the `test' builtin, and may be combined using the following operators: ( EXPRESSION ) Returns the value of EXPRESSION
! EXPRESSION True if EXPRESSION is false; else false
EXPR1 && EXPR2 True if both EXPR1 and EXPR2 are true; else false
EXPR1 || EXPR2 True if either EXPR1 or EXPR2 is true; else false When the `==' and `!=' operators are used, the string to the right of
the operator is used as a pattern and pattern matching is performed.
When the `=~' operator is used, the string to the right of the operator
is matched as a regular expression. The && and || operators do not evaluate EXPR2 if EXPR1 is sufficient to
determine the expression's value. Exit Status:
or depending on value of EXPRESSION.
####.与source是一样的,就不再述。
[root@-shiyan frag]# help .
.: . filename [arguments]
Execute commands from a file in the current shell.
####在当前shell中,从一个文件中执行命令。
Read and execute commands from FILENAME in the current shell. The
entries in $PATH are used to find the directory containing FILENAME.
If any ARGUMENTS are supplied, they become the positional parameters
when FILENAME is executed.
####在当前shell中,从FILENAME中读取并执行命令。在$PATH中的项目是被用作查找包括FILENAME的目录。当FILENAME被执行时,如果有参数供应,他们将成为位置参数。
Exit Status:
Returns the status of the last command executed in FILENAME; fails if
FILENAME cannot be read. [root@-monitor ~]# cat a
#!/bin/bash
ip_conns=`ssh $ "netstat -ant| grep EST | wc -l"`
echo $ip_conns
[root@-monitor ~]# . a 192.168.2.109 [root@-monitor ~]# . a 192.168.2.2 [root@-monitor ~]# source a 192.168.2.225 [root@-monitor ~]# source a 192.168.2.2
[root@-shiyan frag]# help let
let: let arg [arg ...]
Evaluate arithmetic expressions. Evaluate each ARG as an arithmetic expression. Evaluation is done in
fixed-width integers with no check for overflow, though division by
is trapped and flagged as an error. The following list of operators is
grouped into levels of equal-precedence operators. The levels are listed
in order of decreasing precedence.
####按照优先级的降序列出
id++, id-- variable post-increment, post-decrement
++id, --id variable pre-increment, pre-decrement
-, + unary minus, plus
!, ~ logical and bitwise negation
** exponentiation
*, /, % multiplication, division, remainder
+, - addition, subtraction
<<, >> left and right bitwise shifts
<=, >=, <, > comparison
==, != equality, inequality
& bitwise AND
^ bitwise XOR
| bitwise OR
&& logical AND
|| logical OR
expr ? expr : expr
conditional operator
=, *=, /=, %=,
+=, -=, <<=, >>=,
&=, ^=, |= assignment Shell variables are allowed as operands. The name of the variable
is replaced by its value (coerced to a fixed-width integer) within
an expression. The variable need not have its integer attribute
turned on to be used in an expression. ####shell变量被允许作为操作数。在一个表达式里,变量的名字被替换为它的值。 Operators are evaluated in order of precedence. Sub-expressions in
parentheses are evaluated first and may override the precedence
rules above.
####操作符按照优先顺序被求值,在小括号里的子表达式首先被求值,并且可以覆盖上文的优先规则。 Exit Status:
If the last ARG evaluates to , let returns ; let returns otherwise.. [root@-shiyan frag]# let num=+/;echo $num [root@-shiyan frag]# let num=(+)/;echo $num [root@-shiyan frag]# let num=*;echo $num [root@-shiyan frag]# let num=/;echo $num [root@-shiyan frag]# help \(
(( ... )): (( expression ))
Evaluate arithmetic expression. The EXPRESSION is evaluated according to the rules for arithmetic
evaluation. Equivalent to "let EXPRESSION". Exit Status:
Returns if EXPRESSION evaluates to ; returns otherwise. shell里的4种运算格式,只有bc与awk可以浮点运算,其它三个只能整数运算。
[root@-shiyan frag]# ((num=+));echo $num [root@-shiyan frag]# let "num=5+2";echo $num [root@-shiyan frag]# x=`expr \* `;echo $x [root@-shiyan frag]# echo "$(echo 'scale=2;40*100/90' | bc)%"
44.44%
while loop 的原理与 for loop 稍有不同:它不是逐次处理清单中的变量值,而是取决于 while 后面的命令行之 return value :
* 若为 ture ,则执行 do 与 done 之间的命令,然后重新判断 while 后的 return value 。
* 若为 false ,则不再执行 do 与 done 之间的命令而结束循环。
* 若 while 的测试结果永远为 true 的话,那循环将一直永久执行下去:
一旦你能够理解 while loop 的话,那就能理解 until loop :
* 与 while 相反,until 是在 return value 为 false 时进入循环,否则结束。
在结束本shell之前,再跟大家补充两个与 loop 有关的命令:
* break
* continue
这两个命令常用在复合式循环里,也就是在do ... done之间又有更进一层的 loop,当然,用在单一循环中也未尝不可啦... ^_^
break 是用来打断循环,也就是"强迫结束" 循环。若 break 后面指定一个数值 n 的话,则"从里向外"打断第 n 个循环,默认值为 break ,也就是打断当前的循环。
在使用 break 时需要注意的是,它与 return 及 exit 是不同的:
* break 是结束 loop
* return 是结束 function
* exit 是结束 script/shell
而 continue 则与 break 相反:强迫进入下一次循环动作。若你理解不来的话,那你可简单的看成:在 continue 到 done 之间的句子略过而返回循环顶端...与 break 相同的是:continue 后面也可指定一个数值 n ,以决定继续哪一层(从里向外计算)的循环,默认值为 continue ,也就是继续当前的循环。 continue
恢复下一次迭代循环,本次就不执行了
下面这个脚本说明,如果文件名中有while,则不输出,如果想要只输出while行,只需要将=改为!=即可。这就是continue的作用。
#!/bin/bash
for shname in `ls *.sh`
do
  name=`echo "$shname" | awk -F. '{print $1}'`
  if [ $name = while ]
  then
  continue
  fi
  echo $name
done
符合条件的,结束本次循环
[root@-shiyan frag]# bash con1
the number is:
the number is:
the number is:
the number is:
the number is:
the number is:
[root@-shiyan frag]# cat con1
for i in `seq `
do
if [ $i -gt ] && [ $i -lt ]
then
continue
fi
echo "the number is:$i"
done
[root@-shiyan frag]# bash con1
the number is:
the number is:
the number is:
the number is:
the number is:
the number is:
the number is:
the number is:
[root@-shiyan frag]# cat con1
for i in `seq `
do
if [ $i -eq ] || [ $i -eq ]
then
continue
fi
echo "the number is:$i"
done break
退出本层循环
[root@-shiyan frag]# bash con1
please input:q
[root@-shiyan frag]# bash con1
please input:Q
[root@-shiyan frag]# bash con1
please input:
the number is:
the number is:
the number is:
the number is:
the number is:
the number is:
the number is:
the number is:
the number is:
the number is:
[root@-shiyan frag]# cat con1
echo -n "please input:"
read num
for i in `seq `
do
if [ "$num" = "q" ] || [ "$num" = "Q" ]
then
break
fi
echo "the number is:$i"
done
[root@-shiyan frag]# bash con1
please input:q
[root@-shiyan frag]# bash con1
please input:Q
[root@-shiyan frag]#
http://www.dedecms.com/knowledge/servers/linux-bsd/2012/0706/2700_2.html

echo "export HISTTIMEFORMAT='%F %T '" >> /etc/profile

当你从命令行执行 history 命令后,通常只会显示已执行命令的序号和命令本身。如果你想要查看命令历史的时间戳,那么可以执行:
# export HISTTIMEFORMAT='%F %T '
[root@-shiyan ~]# history
-- :: set +o history
-- :: history
-- :: echo $HISTSIZE
-- :: env
-- :: env|grep HIS
-- :: vi .bash_history
-- :: echo $HISTSIZE
-- :: vi /etc/profile
-- :: exit
-- :: history
-- :: free
-- :: vmstat
-- :: history
-- :: exit
-- :: history
-- :: shopt -p
-- :: exit
-- :: history
[root@-shiyan ~]# cat .bash_history
free
#
vmstat
#
history
#
exit
#
history
#
shopt -p
#
exit

[root@250-shiyan ~]# echo !yum:1
echo install
install
注意:这个功能只能用在当 HISTTIMEFORMAT 这个环境变量被设置之后,之后的那些新执行的 bash 命令才会被打上正确的时间戳。在此之前的所有命令,都将会显示成设置 HISTTIMEFORMAT 变量的时间。

shell变量仅供shell builtins,function,keyword,来使用。
环境变量供shell以外的程序来使用。
shell变量
HISTFILE
HISTSIZE
HISTFILESIZE
HISTTIMEFORMAT
HISTCONTROL
HISTIGNORE shell选项
cmdhist
lithist
histappend declare或typeset内建命令(它们是完全相同的)可以用来限定变量的属性.这是在某些编程语言中使用的定义类型不严格的方式。命令declare是bash版本2之后才有的。命令typeset也可以在ksh脚本中运行。
功能说明:声明 shell 变量。
语  法:declare [+/-][rxi][变量名称=设置值] 或 declare -f
补充说明:declare为shell指令,在第一种语法中可用来声明变量并设置变量的属性([rix]即为变量的属性),在第二种语法中可用来显示shell函数。若不加上任何参数,则会显示全部的shell变量与函数(与执行set指令的效果相同)。
参  数:
 +/-  "-"可用来指定变量的属性,"+"则是取消变量所设的属性。
 -f  仅显示函数。
 r  将变量设置为只读。
 x  指定的变量会成为环境变量,可供shell以外的程序来使用。
 i  [设置值]可以是数值,字符串或运算式。
declare/typeset 选项
-r 只读
declare -r var1
(declare -r var1与readonly var1作用相同)
这大致和C的const限定词相同.一个试图改变只读变量值的操作将会引起错误信息而失败.
[root@localhost ~]# rpm -qf /etc/security/
pam-1.1.1-13.el6.x86_64
下面的几个文件是由pam生成的,它也会影响到资源限制。
/etc/security/limits.conf
/etc/security/limits.d
/etc/security/limits.d/90-nproc.conf 先查看块大小,得到单位为K。
[root@localhost ~]# dumpe2fs /dev/sda1 |grep "Block size"
dumpe2fs 1.41. (-May-)
Block size:
再做设置,限制为204M,加入到启动文件中。
[root@localhost ~]# grep ulimit .bash_profile
ulimit -f
然后重新登录,再查看
[root@localhost ~]# ulimit -a|grep "file size"
core file size (blocks, -c)
file size (blocks, -f)
[root@localhost ~]# dd if=/dev/zero of=.img
File size limit exceeded
[root@localhost ~]# ll
total
-rw-r--r--. root root May
-rw-r--r--. root root Feb : .img
-rw-r--r--. root root Feb : .img
-rw-r--r--. root root Feb : .img
-rw-r--r--. root root Feb : .img
由此可知,ulimit -f不限制由此终端的shell的总文件大小,而是单次上限。 pending signals  未处理信号,等待信号。

删除除某个目录之外的所有
只需要开启下面这个模式匹配功能,就可以用除*,?之外的通配符了
shopt -s extglob
rm -rf !(bbs)
rm -rf !(bbs|cc)
删除当前目录下除bbs目录外所有的文件,真方便
也可以用下面的这条命令
ls |grep -v bbs |xargs rm -f

[root@cs-manage sh]# ffile=/dir1/dir2/dir3/my.file.txt
[root@cs-manage sh]# echo ${ffile/dir/}
/1/dir2/dir3/my.file.txt
[root@cs-manage sh]# echo ${ffile//dir/}
/1/2/3/my.file.txt
[root@cs-manage sh]# echo ${ffile/#/oi}
oi/dir1/dir2/dir3/my.file.txt
[root@cs-manage sh]# echo ${ffile/%/oi}
/dir1/dir2/dir3/my.file.txtoi
[root@cs-manage sh]# echo ${ffile/%t/oi}
/dir1/dir2/dir3/my.file.txoi

Bash的=~正则表达式匹配
http://zengrong.net/post/1563.htm

简洁的bash编程技巧
http://www.open-open.com/lib/view/open1352264103719.html

bash内部命令-2的更多相关文章

  1. bash内部命令-1

    外置命令 date expr seq nohup tput bash内置命令 trap set shopt date Linux时钟分为系统时钟(System Clock)和硬件(Real Time ...

  2. shell-的bash内部命令变量介绍与shift等

    一:shell的bash内部命令变量介绍与shift等 1. bash内部变量     有些内部命令在目录列表时是看不见的,他们有shell本身提供,常用的内部命令有:echo,eval,exec,e ...

  3. Bash 中同名的内部命令和外部命令

    昨天有个人在 bug-bash 上问:为什么 [ --help 没有输出帮助信息.有人回答他了,原因是 coreutils 提供的 [ 命令才接受 --help 选项,Bash 自己的 [ 命令不接受 ...

  4. bash功能——命令行编辑、内部命令 外部命令、命令补全 、命令历史、文件名通配符、命令别名

    命令行编辑: Ctrl + a : 跳转到当前编辑行首 Ctrl + e:跳转到当前编辑行尾 # mkdir /home/dira /home/diab 像这种命令,/home/dira 和 /hom ...

  5. cmd 与 bash 基础命令入门

    身为一个程序员会用命令行来进行一些简单的操作,不是显得很装逼嘛!?嘿嘿~ ヾ(>∀<) cmd 与 bash 基础命令入门       简介       CMD 基础命令          ...

  6. bash 基础命令

    bash的基础特性(): () 命令历史 history 环境变量: HISTSIZE:命令历史记录的条数: HISTFILE:~/.bash_history: HISTFILESIZE:命令历史文件 ...

  7. Linux Shell基础 Bash常见命令 history、alias命令以及常用快捷键

    概述  shell中常见命令history 历史纪录命令:history 命令格式如下: [root@localhost ~]# history [选项] [历史命令保存文件] -c:清空历史命令: ...

  8. Linux shell 内部命令与外部命令有什么区别以及怎么辨别

    内部命令实际上是shell程序的一部分,其中包含的是一些比较简单的linux系统命令,这些命令由shell程序识别并在shell程序内部完成运行,通常在linux系统加载运行时shell就被加载并驻留 ...

  9. 8.bash编辑命令行

    8.编辑命令行本章介绍 GNU 命令行编辑界面的基本功能.命令行编辑是 Readline 库提供的:这个库被几个不同的程序共用,Bash 是其中一个.使用交互式的 shell 时,默认已经打开了命令行 ...

随机推荐

  1. JAVA判断当前时间是上午am还是下午pm

    //结果为"0"是上午 结果为"1"是下午 public class GregorianTest { public static void main(Strin ...

  2. BZOJ 1951 古代猪文

    快速幂+枚举质因数+欧拉定理+lucas定理+CRT. 注意两点: 1.if (n<m) C(n,m)=0. 2.这里0^0时应该return 0. #include<iostream&g ...

  3. 【Tsinghua OJ】循环移位(Cycle)

    Description Cycle shifting refers to following operation on the sting. Moving first letter to the en ...

  4. php 安装composer

    右击我的电脑 再属性 再高级 再环境变量 再系统变量里有个path 双击打开来 把你的PHP路径 加个分号再前面 添加进去就OK了 1.http://www.th7.cn/Program/php/20 ...

  5. 日历控件修改的JS代码

    var bMoveable=true; var _VersionInfo=" " ; //============================================= ...

  6. DB Create and Insert

    <?php $servername = "localhost"; $username = "username"; $password = "pa ...

  7. 一个经典例子让你彻彻底底理解java回调机制

    转帖请注明本文出自xiaanming的博客(http://blog.csdn.net/xiaanming/article/details/17483273),请尊重他人的辛勤劳动成果,谢谢 所谓回调: ...

  8. jquery模拟淘宝购物车

    今天要实现的一个功能页面就是利用jquery代码模拟一个淘宝网的购物车结算页面 总体页面效果如图: 首先我们要实现的内容的需求有如下几点: 1.在购物车页面中,当选中“全选”复选框时,所有商品前的复选 ...

  9. 解决div里插入img下边缝隙问题

    <html>   <head>   <title> new document </title>   <meta name="author ...

  10. 重学STM32---(七) FSMC+LCD

    关于FSMC+LCD第一次学习完时候,自己也还是对这个不清不白,时而清楚,时而糊涂.这一次再次学习的话,不能在这样了,仔仔细细把STM32参考手册,原子的LCD实验看了一遍,又在网上找了好些关于FSM ...