shell 算术运算操作

2015-6-2 杜世伟 Linux

算术运算符指的是可以在程序中实现加、减、乘、除等数学运算的运算符。
Shell中常用的数学运算符如下所示。
 +:对两个变量做加法。
 -:对两个变量做减法。
 *:对两个变量做乘法。
 /:对两个变量做除法。
 **:对两个变量做幂运算。
 %:取模运算,第一个变量除以第二个变量求余数。
 +=:加等于,在自身基础上加第二个变量。
 -=:减等于,在第一个变量的基础上减去第二个变量。
 *=:乘等于,在第一个变量的基础上乘以第二个变量。
 /=:除等于,在第一个变量的基础上除以第二个变量。
 %=:取模赋值,第一个变量对第二个变量取模运算,再赋值给第一个变量。

阅读全文>>

标签: linux shell

评论(0) 浏览(9735)

Linux下安装 Memcached服务器端

2015-5-27 杜世伟 memcache

#!/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 ..

阅读全文>>

标签: linux memcache memcached

评论(0) 浏览(13156)

./configure: error: SSL modules require the OpenSSL library

2015-5-19 杜世伟 Linux

make: *** No rule to make target `build', needed by `default'. Stop. ./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source

with nginx by using --with-openssl= option.


yum -y install openssl openssl-devel

标签: openssl openssl-devel

评论(0) 浏览(4346)

CentOS 7.0关闭默认防火墙启用iptables防火墙

2015-5-16 杜世伟 Linux

操作系统环境: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

阅读全文>>

标签: iptables centos firewall

评论(0) 浏览(14751)

phpize Cannot find autoconf

2015-5-10 杜世伟 Php

Centos下执行phpize提示“Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this scrIPt.”
原因:缺少autoconf
解决方法:
yum install autoconf

标签: PHP phpize autoconf

评论(0) 浏览(16574)

vim 删除指定的行

2015-5-3 杜世伟 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

阅读全文>>

标签: linux vim

评论(0) 浏览(5157)

shell脚本基本IF条件判断和判断条件总结

2015-4-30 杜世伟 Linux

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 shell

评论(0) 浏览(15058)

linux find 统计目录下信息

2015-4-17 杜世伟 Linux

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

转载标明来源!

阅读全文>>

标签: linux find

评论(0) 浏览(9850)

lua 中的assert 与loadstring 问题

2015-4-13 杜世伟 Lua

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

评论(0) 浏览(4805)

Lua编译与运行

2015-4-12 杜世伟 Lua

   Lua是解释性语言,但Lua会首先把代码预编译成中间码然后再执行。不要以为需要编译就不是解释型语言,Lua的编译器是语言运行时的一部分,所以,执行编译产生中间码速度会更快。

  dofile/dostring和loadfile/loadstring的区别:

  (1)do*会编译并执行;load*只编译代码生成中间码并且返回编译后的chunk作为一个函数,但不执行代码。

  (2)load*较为灵活,发生错误时load*会返回nil和错误信息(可以打印出来)。

  (3)如果要运行一个文件多次,load*只需要编译一次,但可以多次运行,do*每次都需要编译。

  (4)dostring(str)等价于loadstring(str)()

阅读全文>>

标签: lua loadstring dofile dostring loadfile

评论(0) 浏览(4546)

Powered by emlog 沪ICP备2023034538号-1