<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title> &#187; Shell</title>
	<atom:link href="http://www.liguosong.com/category/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.liguosong.com</link>
	<description></description>
	<lastBuildDate>Tue, 08 May 2018 01:02:19 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.2</generator>
		<item>
		<title>mac 使用oh my zsh后，.bash_profile失效的问题</title>
		<link>http://www.liguosong.com/2015/04/29/mac-%e4%bd%bf%e7%94%a8oh-my-zsh%e5%90%8e%ef%bc%8c-bash_profile%e5%a4%b1%e6%95%88%e7%9a%84%e9%97%ae%e9%a2%98/</link>
		<comments>http://www.liguosong.com/2015/04/29/mac-%e4%bd%bf%e7%94%a8oh-my-zsh%e5%90%8e%ef%bc%8c-bash_profile%e5%a4%b1%e6%95%88%e7%9a%84%e9%97%ae%e9%a2%98/#comments</comments>
		<pubDate>Wed, 29 Apr 2015 03:14:44 +0000</pubDate>
		<dc:creator>lgs</dc:creator>
				<category><![CDATA[Shell]]></category>

		<guid isPermaLink="false">http://www.liguosong.com/?p=481</guid>
		<description><![CDATA[最近使用了oh my zsh，发现原来的环境变量都不能用了。查看了一下.zshrc的内容，发现里面把原来的pa [...]]]></description>
				<content:encoded><![CDATA[<p>最近使用了oh my zsh，发现原来的环境变量都不能用了。查看了一下.zshrc的内容，发现里面把原来的path给覆盖了。如下图，所以我又重新的加载了一下原来的.bash_profile文件。问题解决了。<a href="http://www.liguosong.com/wp-content/uploads/2015/04/F94290BA-2C95-48C5-A4BC-3E010E8F5C9D.jpg"><img class="alignnone size-full wp-image-482" alt="F94290BA-2C95-48C5-A4BC-3E010E8F5C9D" src="http://www.liguosong.com/wp-content/uploads/2015/04/F94290BA-2C95-48C5-A4BC-3E010E8F5C9D.jpg" width="1350" height="174" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.liguosong.com/2015/04/29/mac-%e4%bd%bf%e7%94%a8oh-my-zsh%e5%90%8e%ef%bc%8c-bash_profile%e5%a4%b1%e6%95%88%e7%9a%84%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux df 查看磁盘使用情况</title>
		<link>http://www.liguosong.com/2014/09/18/linux-df-%e6%9f%a5%e7%9c%8b%e7%a3%81%e7%9b%98%e4%bd%bf%e7%94%a8%e6%83%85%e5%86%b5/</link>
		<comments>http://www.liguosong.com/2014/09/18/linux-df-%e6%9f%a5%e7%9c%8b%e7%a3%81%e7%9b%98%e4%bd%bf%e7%94%a8%e6%83%85%e5%86%b5/#comments</comments>
		<pubDate>Thu, 18 Sep 2014 07:23:30 +0000</pubDate>
		<dc:creator>lgs</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[linux df]]></category>

		<guid isPermaLink="false">http://www.liguosong.com/?p=413</guid>
		<description><![CDATA[df 查看系统磁盘的使用情况 常用参数： -a, --all 显示所有的文件系统 --total 对df结果， [...]]]></description>
				<content:encoded><![CDATA[<p>df 查看系统磁盘的使用情况</p>
<p>常用参数：</p>
<pre class="brush:bash">       -a, --all  
              显示所有的文件系统

       --total
              对df结果，进行汇总，在最下面输出一行每列的总数

       -h, --human-readable
              将结果的数字转换成更加易读的格式。这个参数很好用

       -H, --si
              与-h作用，但是计算使用1000进制，而不是1024

       -i, --inodes
              显示i节点信息，而不是磁盘块

       -k     like --block-size=1K
              将空间的结果，以kb为单位显示

       -l, --local
              只显示本地文件系统

       --no-sync
              忽略 sync 命令

       -P, --portability
              输出格式为POSIX

       --sync
             在取得磁盘信息前，先执行sync命令

       -t, --type=TYPE
              只显示特定类型的文件系统。如只显示ext4的，可以用 df -t ext4 或者 df --type=ext4

       -T, --print-type
              显示文件系统的类型

       -x, --exclude-type=TYPE
              显示不是指定类型的文件系统，与-t使用相反。如想显示不是ext4类型的文件系统，可以用 df -x ext4 或者df --exclude-type=ext4
       --version 查看版本信息
       --help 获取帮助信息</pre>
<p>更多参数使用如下命令查看：</p>
<pre>man df
或者
df --help</pre>
<p><span style="line-height: 1.714285714; font-size: 1rem;">例子：看磁盘占用空间，还剩多少空间。</span></p>
<pre class="brush:other">df -lh</pre>
<p>结果：</p>
<pre class="brush:other">Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       20G  6.8G   13G  36% /
udev            993M  4.0K  993M   1% /dev
tmpfs           201M  284K  200M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none           1002M     0 1002M   0% /run/shm
/dev/xvdb1       40G   33G  4.6G  88% /mnt</pre>
<p>解释：</p>
<p>Filesystem：文件系统<br />
Size：总共大小<br />
Used：使用大小<br />
Avail：可用<br />
Mounted on：挂在分区</p>
<p>如果要查看一个文件系统的信息，可以这样写</p>
<pre class="brush:other">df -h /mnt</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liguosong.com/2014/09/18/linux-df-%e6%9f%a5%e7%9c%8b%e7%a3%81%e7%9b%98%e4%bd%bf%e7%94%a8%e6%83%85%e5%86%b5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>shell结构化命令if-then-elif-fi</title>
		<link>http://www.liguosong.com/2014/01/05/shell%e7%bb%93%e6%9e%84%e5%8c%96%e5%91%bd%e4%bb%a4if-then-elif-fi/</link>
		<comments>http://www.liguosong.com/2014/01/05/shell%e7%bb%93%e6%9e%84%e5%8c%96%e5%91%bd%e4%bb%a4if-then-elif-fi/#comments</comments>
		<pubDate>Sun, 05 Jan 2014 13:06:39 +0000</pubDate>
		<dc:creator>lgs</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[shell if]]></category>

		<guid isPermaLink="false">http://www.liguosong.com/?p=234</guid>
		<description><![CDATA[在编写shell中，很少有脚本是顺序操作，大部分的时候需要进行逻辑判断。 先看一个简单的格式： if comm [...]]]></description>
				<content:encoded><![CDATA[<p>在编写shell中，很少有脚本是顺序操作，大部分的时候需要进行逻辑判断。<br />
先看一个简单的格式：</p>
<pre class="brush:bash">if command
then
    commands
fi</pre>
<p>bash shell会运行if后面的命令。如果该命令的退出状态码是0，then后的命令就会执行。否则不执行。<span id="more-234"></span>来个简单的例子：</p>
<pre class="brush:bash">#!/bin/sh
workPath=/Users/liguosong/work/shell
if cd $workPath
then
     echo Ok
fi</pre>
<p>如果这个路径存在，就会输出Ok。</p>
<p>上面是一个很单间的if语句。其它语言都会有else，else if语句。shell也有。如果if后面的命令执行结果是非零，就会执行else部分。先来一个简单的else的例子：</p>
<pre class="brush:bash">#!/bin/sh
workPath=/Users/liguosong/work/shell
if cd $workPath
then
    echo Ok
else
    echo Path not exist.
fi</pre>
<p>有时候需要进行多种条件判断，shell中我们可以用elif。基本的结构：</p>
<pre class="brush:bash">if command
then
    commands
elif command2
then
    commands
fi</pre>
<p>上面的结构，只是普通的shell命令，if的条件是否成立都是与状态码有关的。那么把其它条件作为if判断的依据，那么我们就要学习下面的test命令了。</p>
<p>shell test命令</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liguosong.com/2014/01/05/shell%e7%bb%93%e6%9e%84%e5%8c%96%e5%91%bd%e4%bb%a4if-then-elif-fi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell 反引号 `</title>
		<link>http://www.liguosong.com/2014/01/04/shell-%e5%8f%8d%e5%bc%95%e5%8f%b7/</link>
		<comments>http://www.liguosong.com/2014/01/04/shell-%e5%8f%8d%e5%bc%95%e5%8f%b7/#comments</comments>
		<pubDate>Sat, 04 Jan 2014 06:44:12 +0000</pubDate>
		<dc:creator>lgs</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[shell 反引号]]></category>

		<guid isPermaLink="false">http://www.liguosong.com/?p=226</guid>
		<description><![CDATA[shell脚本中的反引号“`”,这个符号通常在tab键的上面那个键，同时按住shift输入。在shell中反引 [...]]]></description>
				<content:encoded><![CDATA[<p>shell脚本中的反引号“`”,这个符号通常在tab键的上面那个键，同时按住shift输入。在shell中反引号，可以讲命令的输出赋给变量。在shell编程中，很多时候，shell 命令的输出需要作为下面命令的参数。那这个反引号就会排上用场了。<br />
这个例子很简单，就是按照年月日，创建文件夹。<span id="more-226"></span>代码如下：</p>
<pre class="brush:bash">#!/bin/sh
DATE=`date +%Y%m%d`
mkdir $DATE</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liguosong.com/2014/01/04/shell-%e5%8f%8d%e5%bc%95%e5%8f%b7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell 函数</title>
		<link>http://www.liguosong.com/2014/01/01/shell-%e5%87%bd%e6%95%b0/</link>
		<comments>http://www.liguosong.com/2014/01/01/shell-%e5%87%bd%e6%95%b0/#comments</comments>
		<pubDate>Wed, 01 Jan 2014 10:46:54 +0000</pubDate>
		<dc:creator>lgs</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[shell 函数]]></category>

		<guid isPermaLink="false">http://www.liguosong.com/?p=220</guid>
		<description><![CDATA[在开始编写复杂的shell脚本时，有时候你会发现在编写很多重复的代码。bash shell支持用户定义的函数。 [...]]]></description>
				<content:encoded><![CDATA[<p>在开始编写复杂的shell脚本时，有时候你会发现在编写很多重复的代码。bash shell支持用户定义的函数。可以将shell脚本的代码进行封装。方便以后多次使用和维护。<span id="more-220"></span></p>
<p>有两种方式可以创建bash shell的函数：<br />
方式一：采用关键字function，后面跟着函数名称。例如：</p>
<pre class="brush:bash">#!/bin/bash

function hello {
	echo This is hello function.
}

hello</pre>
<p><em>输出结果：<br />
This is hello function.</em></p>
<p><strong> 注意： 方法与后面的大括号要有空格，不可以写成 Hello{  这样是错误的。</strong></p>
<p>方式二：不实用function关键字。直接是方法的名字。例如：</p>
<pre class="brush:bash">#!/bin/bash

hello() {
	echo This is hello function.
}

hello</pre>
<p><em>输出结果：<br />
This is hello function.</em></p>
<p><strong>第二种方法，函数名和后面的小括号和大括号可以有空格也可以没有。不过建议在大括号写一个空格。</strong></p>
<p><strong>注意：再调用函数的时候，函数定义必须在调用之前定义。<br />
如果在同一个shell中重复定义了一个函数，不会产生任何错误。后续使用该函数，都会使用第二个定义的函数。例如：</strong></p>
<pre class="brush:bash">#!/bin/bash

hello() {
	echo This is hello function.
}

hello

hello() {
	echo This is a repeat of the hello function.
}

hello</pre>
<p><em>输出结果：<br />
</em>This is hello function.<br />
This is a repeat of the hello function.</p>
<p>这只是简单的函数，没有参数，没有返回值。<br />
继续研究一下bash shell 如何获取函数退出状态码。可以说有三种返回值：<br />
方式一：<br />
默认状态下，函数的退出状态码是函数中执行最后一条命令的退出状态码，可以用$?获取状态码。例如：</p>
<pre class="brush:bash">testReturn() {
	echo Hello
}

testReturn

echo The exit status is $?</pre>
<p>输出结果：<br />
0</p>
<p>方式二：使用return。return命令允许指定一个数值作为函数的退出状态码。</p>
<pre class="brush:bash">testReturn() {
	return 10
}

testReturn
echo The exit status is $?</pre>
<p>输出结果：10<br />
注意：退出状态码必须在0-255之间。要是返回较大的数值或者字符串，必须使用下面的方法了。</p>
<p>方法三：将函数的输出保存到shell变量中。</p>
<pre class="brush:bash">#!/bin/bash

testReturn() {
	echo Hello
}

RESULT=`testReturn`
echo $RESULT</pre>
<p>输出结果：Hello</p>
]]></content:encoded>
			<wfw:commentRss>http://www.liguosong.com/2014/01/01/shell-%e5%87%bd%e6%95%b0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
