shell 算术运算操作
算术运算符指的是可以在程序中实现加、减、乘、除等数学运算的运算符。Shell中常用的数学运算符如下所示。
+:对两个变量做加法。
-:对两个变量做减法。
*:对两个变量做乘法。
/:对两个变量做除法。
**:对两个变量做幂运算。
%:取模运算,第一个变量除以第二个变量求余数。
+=:加等于,在自身基础上加第二个变量。
-=:减等于,在第一个变量的基础上减去第二个变量。
*=:乘等于,在第一个变量的基础上乘以第二个变量。
/=:除等于,在第一个变量的基础上除以第二个变量。
%=:取模赋值,第一个变量对第二个变量取模运算,再赋值给第一个变量。
Linux下安装 Memcached服务器端
#!/bin/sh#Author : shiwei.du
#Date : 2016/04/08
#install libevent
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
tar zxvf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix=/usr/
make && make install
cd ..
./configure: error: SSL modules require the OpenSSL library
with nginx by using --with-openssl= option.
yum -y install openssl openssl-devel
标签: openssl openssl-devel
CentOS 7.0关闭默认防火墙启用iptables防火墙
操作系统环境:CentOS Linux release 7.0.1406(Core) 64位CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。
1、关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
2、iptables防火墙(这里iptables已经安装,下面进行配置)
vi/etc/sysconfig/iptables #编辑防火墙配置文件
# sampleconfiguration for iptables service
# you can edit thismanually or use system-config-firewall
# please do not askus to add additional ports/services to this default configuration
phpize Cannot find autoconf
Centos下执行phpize提示“Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this scrIPt.”原因:缺少autoconf
解决方法:
yum install autoconf
vim 删除指定的行
vim 删除指定的行
#-----命令行模式下------
1.删除以#开头的行:g/^#.*$/d
2.删除以//开头的行:
g/^\/\/.*$/d
3.删除空白行:
g/^$/d
4.刪除包含有空格組成的空行
g/^\s*$/d
5.删除以空格或tab開頭到結尾的空行
g/^[ |\t]*$/d
原创转载请注明来源:https://www.dushiwei.cn/post/461
shell脚本基本IF条件判断和判断条件总结
1、基本语法:if [ command ]; then
符合该条件执行的语句
fi
2、扩展语法:
if [ command ];then
符合该条件执行的语句
elif [ command ];then
符合该条件执行的语句
else
符合该条件执行的语句
fi
3、语法说明:
bash shell会按顺序执行if语句,如果command执行后且它的返回状态是0,则会执行符合该条件执行的语句,否则后面的命令不执行,跳到下一条命令。
当有多个嵌套时,只有第一个返回0退出状态的命令会导致符合该条件执行的语句部分被执行,如果所有的语句的执行状态都不为0,则执行else中语句。
返回状态:最后一个命令的退出状态,或者当没有条件是真的话为0。
linux find 统计目录下信息
linux find 目录统计下信息
linux 环境下通过find命令对目录下信息进行统计
1.统计/data/www-data目录下,php文件数量:find /data/www-data/ -name "*.php" |wc -l
2.统计demo目录下所有php文件代码行数:
find /data/www-data/ -name "*.php" |xargs cat|wc -l 或 wc -l `find ./ -name "*.php"`|tail -n1
3.统计/data/www-data/目录下所有php文件代码行数,过滤了空行:
find /data/www-data/ -name "*.php" |xargs cat|grep -v ^$|wc -l
转载标明来源!
lua 中的assert 与loadstring 问题
loadstring 通过加载一个符合lua语言规范的字符串 返回一个lua function,
例如:
local str = "print 'dushiwei.cn'"
local str = loadstring(str)
assert(str)()
local str = "print 'dushiwei.cn'"
local str = loadstring(str)
等价于 local script = function()
print 'dushiwei.cn'
end
标签: lua loadstring assert
Lua编译与运行
Lua是解释性语言,但Lua会首先把代码预编译成中间码然后再执行。不要以为需要编译就不是解释型语言,Lua的编译器是语言运行时的一部分,所以,执行编译产生中间码速度会更快。
dofile/dostring和loadfile/loadstring的区别:
(1)do*会编译并执行;load*只编译代码生成中间码并且返回编译后的chunk作为一个函数,但不执行代码。
(2)load*较为灵活,发生错误时load*会返回nil和错误信息(可以打印出来)。
(3)如果要运行一个文件多次,load*只需要编译一次,但可以多次运行,do*每次都需要编译。
(4)dostring(str)等价于loadstring(str)()
热门日志
分类
- Django(4)
- ssdb(1)
- Mac(7)
- C(1)
- memcache(1)
- Python(32)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- about(1)
- git(9)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(2)
- 架构(18)
- Vue(1)
- game(2)
- Html(6)
- Java(8)
- Mysql(37)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(72)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Php(102)
- Windows(8)
- Message(48)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(12)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)