代码拉取完成,页面将自动刷新
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
每天学习一个shell技能(6) - kaelinda
</title>
<link href="atom.xml" rel="alternate" title="kaelinda" type="application/atom+xml">
<link rel="stylesheet" href="asset/css/foundation.min.css" />
<link rel="stylesheet" href="asset/css/docs.css" />
<script src="asset/js/vendor/modernizr.js"></script>
<script src="asset/js/vendor/jquery.js"></script>
<script src="asset/highlightjs/highlight.pack.js"></script>
<link href="asset/highlightjs/styles/github.css" media="screen, projection" rel="stylesheet" type="text/css">
<script>hljs.initHighlightingOnLoad();</script>
<script type="text/javascript">
function before_search(){
var searchVal = 'site:kaelinda.top ' + document.getElementById('search_input').value;
document.getElementById('search_q').value = searchVal;
return true;
}
</script>
</head>
<body class="antialiased hide-extras">
<div class="marketing off-canvas-wrap" data-offcanvas>
<div class="inner-wrap">
<nav class="top-bar docs-bar hide-for-small" data-topbar>
<section class="top-bar-section">
<div class="row">
<div style="position: relative;width:100%;"><div style="position: absolute; width:100%;">
<ul id="main-menu" class="left">
<li id=""><a target="_self" href="index.html">最近更新</a></li>
<li id=""><a target="_self" href="archives.html">归档目录</a></li>
<li id="ios.css"><a target="_self" href="ios.html">iOS</a></li>
<li id="swift.css"><a target="_self" href="swift.html">Swift</a></li>
<li id="reactnative.css"><a target="_self" href="reactnative.html">RN</a></li>
<li id="js.css"><a target="_self" href="js.html">JS</a></li>
<li id="shell.css"><a target="_self" href="shell.html">shell</a></li>
<li id="coding.css"><a target="_self" href="coding.html">编程</a></li>
<li id="live.css"><a target="_self" href="live.html">随笔</a></li>
<li id="app.css"><a target="_blank" href="app.html">APP推荐</a></li>
</ul>
<ul class="right" id="search-wrap">
<li>
<form target="_blank" onsubmit="return before_search();" action="http://google.com/search" method="get">
<input type="hidden" id="search_q" name="q" value="" />
<input tabindex="1" type="search" id="search_input" placeholder="Search"/>
</form>
</li>
</ul>
</div></div>
</div>
</section>
</nav>
<nav class="tab-bar show-for-small">
<a href="javascript:void(0)" class="left-off-canvas-toggle menu-icon">
<span> kaelinda</span>
</a>
</nav>
<aside class="left-off-canvas-menu">
<ul class="off-canvas-list">
<li><a target="_self" href="index.html">最近更新</a></li>
<li><a target="_self" href="archives.html">归档目录</a></li>
<li><a target="_self" href="ios.html">iOS</a></li>
<li><a target="_self" href="swift.html">Swift</a></li>
<li><a target="_self" href="reactnative.html">RN</a></li>
<li><a target="_self" href="js.html">JS</a></li>
<li><a target="_self" href="shell.html">shell</a></li>
<li><a target="_self" href="coding.html">编程</a></li>
<li><a target="_self" href="live.html">随笔</a></li>
<li><a target="_blank" href="app.html">APP推荐</a></li>
<li><label>Categories</label></li>
<li><a href="reactnative.html">React-Native</a></li>
<li><a href="ios.html">iOS</a></li>
<li><a href="app.html">MacAPP</a></li>
<li><a href="swift.html">Swift</a></li>
<li><a href="js.html">JavaScript</a></li>
<li><a href="vue.html">Vue</a></li>
<li><a href="shell.html">shell</a></li>
<li><a href="%E7%BD%91%E7%BB%9C.html">网络</a></li>
</ul>
</aside>
<a class="exit-off-canvas" href="#"></a>
<section id="main-content" role="main" class="scroll-container">
<script type="text/javascript">
$(function(){
$('#menu_item_index').addClass('is_active');
});
</script>
<div class="row">
<div class="large-8 medium-8 columns">
<div class="markdown-body article-wrap">
<div class="article">
<h1>每天学习一个shell技能(6)</h1>
<div class="read-more clearfix">
<span class="date">2018/4/2</span>
<span>posted in </span>
<span class="posted-in"><a href='shell.html'>shell</a></span>
<span class="comments">
</span>
</div>
</div><!-- article -->
<div class="article-content">
<h2 id="toc_0">test</h2>
<h3 id="toc_1">test文件</h3>
<pre><code class="language-text">if test -e ./test.sh
then
echo '文件已存在!'
else
echo '文件不存在!'
fi
</code></pre>
<ul>
<li>-e fileName : 如果文件存在则为真</li>
<li>-r fileName : 如果文件存在且可读则为真</li>
<li>-w fileName : 如果文件存在且可写则为真</li>
<li>-x fileName : 如果文件存在且可执行则为真</li>
<li>-s fileName: 文件存在且至少有一个字符</li>
<li>-d fileName : 文件存在且为目录</li>
<li>-f fileName: 文件存在且为文件</li>
<li>-c fileName:文件存在,且为字符型特殊文件</li>
<li>-b fileName: 如果文件存在且为块特殊文件则为真</li>
</ul>
<span id="more"></span><!-- more -->
<h3 id="toc_2">test字符串</h3>
<ul>
<li>= :等于则为真</li>
<li>!= :不等于则为真</li>
<li>-z : 字符串长度为零则为真</li>
<li>-n : 字符串长度不为零则为真</li>
</ul>
<h3 id="toc_3">数值测试</h3>
<ul>
<li>-eq :等于</li>
<li>-ne : 不等于</li>
<li>-gt:大于</li>
<li>-lt:小于</li>
<li>-ge:大于等于</li>
<li>-le: 小于等于</li>
</ul>
<h2 id="toc_4">流程控制(条件)</h2>
<h3 id="toc_5">if</h3>
<pre><code class="language-text">if condition
then
command1
command2
...
commandN
fi
</code></pre>
<h3 id="toc_6">if else</h3>
<pre><code class="language-text">if condition
then
command1
command2
...
commandN
else
command
fi
</code></pre>
<h3 id="toc_7">if else-if else</h3>
<pre><code class="language-text">if condition1
then
command1
elif condition2
then
command2
else
commandN
fi
</code></pre>
<p>实例 用法:</p>
<pre><code class="language-text">a=10
b=20
if [ $a == $b ]
then
echo "a 等于 b"
elif [ $a -gt $b ]
then
echo "a 大于 b"
elif [ $a -lt $b ]
then
echo "a 小于 b"
else
echo "没有符合的条件"
fi
</code></pre>
<h2 id="toc_8">控制流(for 循环)</h2>
<pre><code class="language-text">for var in item1 item2 ... itemN
do
command1
command2
...
commandN
done
</code></pre>
<p>改成一行:</p>
<pre><code class="language-text">for var in item1 item2 ... itemN; do command1; command2… done;
</code></pre>
<h2 id="toc_9">while</h2>
<pre><code class="language-text">while condition
do
command
done
</code></pre>
<pre><code class="language-text">int=1
while(( $int<=5 ))
do
echo $int
let "int++"
done
</code></pre>
<p>无限循环:</p>
<pre><code class="language-text">while :
do
command
done
// 或者
while true
do
command
done
// 或者
for (( ; ; ))
</code></pre>
<h2 id="toc_10">until 循环</h2>
<pre><code class="language-text">until condition
do
command
done
</code></pre>
<h2 id="toc_11">case in</h2>
<pre><code class="language-text">case 值 in
模式1)
command1
command2
...
commandN
;;
模式2)
command1
command2
...
commandN
;;
esac
</code></pre>
<h2 id="toc_12">跳出循环</h2>
<h3 id="toc_13">break</h3>
<blockquote>
<p>break命令允许跳出所有循环(终止执行后面的所有循环)</p>
</blockquote>
<h3 id="toc_14">continue</h3>
<blockquote>
<p>continue命令与break命令类似,只有一点差别,它不会跳出所有循环,仅仅跳出当前循环</p>
</blockquote>
<pre><code class="language-text">while :
do
echo -n "输入 1 到 5 之间的数字: "
read aNum
case $aNum in
1|2|3|4|5) echo "你输入的数字为 $aNum!"
;;
*) echo "你输入的数字不是 1 到 5 之间的!"
continue
echo "游戏结束"
;;
esac
done
</code></pre>
<h3 id="toc_15">esac</h3>
<blockquote>
<p>case的语法和C family语言差别很大,它需要一个esac(就是case反过来)作为结束标记,每个case分支用右圆括号,用两个分号表示break。</p>
</blockquote>
</div>
<div class="row">
<div class="large-6 columns">
<p class="text-left" style="padding:15px 0px;">
<a href="15226648731246.html"
title="Previous Post: 每天学习一个shell技能(7)">« 每天学习一个shell技能(7)</a>
</p>
</div>
<div class="large-6 columns">
<p class="text-right" style="padding:15px 0px;">
<a href="15224936933861.html"
title="Next Post: 每天学习一个shell技能(5)">每天学习一个shell技能(5) »</a>
</p>
</div>
</div>
<div class="comments-wrap">
<div class="share-comments">
</div>
</div>
</div><!-- article-wrap -->
</div><!-- large 8 -->
<div class="large-4 medium-4 columns">
<div class="hide-for-small">
<div id="sidebar" class="sidebar">
<div id="site-info" class="site-info">
<div class="site-a-logo"><img src="https://ws1.sinaimg.cn/large/006tNc79ly1fmpk9088gsj30sg0sgn33.jpg" /></div>
<h1>kaelinda</h1>
<div class="site-des">倘若我心中的山水,你眼中能看到,我便一步一莲花祈祷</div>
<div class="social">
<a target="_blank" class="twitter" target="_blank" href="https://twitter.com/KaelLVLinda" title="Twitter">Twitter</a>
<a target="_blank" class="github" target="_blank" href="https://github.com/Kaelzzs" title="GitHub">GitHub</a>
<a target="_blank" class="email" href="mailto:zhouzuosong_kael@163.com" title="Email">Email</a>
<a target="_blank" class="rss" href="atom.xml" title="RSS">RSS</a>
</div>
</div>
<div id="site-categories" class="side-item ">
<div class="side-header">
<h2>Categories</h2>
</div>
<div class="side-content">
<p class="cat-list">
<a href="reactnative.html"><strong>React-Native</strong></a>
<a href="ios.html"><strong>iOS</strong></a>
<a href="app.html"><strong>MacAPP</strong></a>
<a href="swift.html"><strong>Swift</strong></a>
<a href="js.html"><strong>JavaScript</strong></a>
<a href="vue.html"><strong>Vue</strong></a>
<a href="shell.html"><strong>shell</strong></a>
<a href="%E7%BD%91%E7%BB%9C.html"><strong>网络</strong></a>
</p>
</div>
</div>
<div id="site-categories" class="side-item">
<div class="side-header">
<h2>Recent Posts</h2>
</div>
<div class="side-content">
<ul class="posts-list">
<li class="post">
<a href="15523077857608.html">OC中枚举写法 以及 字符串枚举探索</a>
</li>
<li class="post">
<a href="15522686353535.html">iOS 动画全解 (1)</a>
</li>
<li class="post">
<a href="15501356584731.html">UITableView顶部空白的几种解决办法</a>
</li>
<li class="post">
<a href="15488351784332.html">Objective-C中的字符串类型枚举 探索</a>
</li>
<li class="post">
<a href="15409691048860.html">【Swift笔记】引用计数</a>
</li>
</ul>
</div>
</div>
</div><!-- sidebar -->
</div><!-- hide for small -->
</div><!-- large 4 -->
</div><!-- row -->
<div class="page-bottom clearfix">
<div class="row">
<p class="copyright">Copyright © 2015
Powered by <a target="_blank" href="http://www.mweb.im">MWeb</a>,
Theme used <a target="_blank" href="http://github.com">GitHub CSS</a>.</p>
</div>
</div>
</section>
</div>
</div>
<script src="asset/js/foundation.min.js"></script>
<script>
$(document).foundation();
function fixSidebarHeight(){
var w1 = $('.markdown-body').height();
var w2 = $('#sidebar').height();
if (w1 > w2) { $('#sidebar').height(w1); };
}
$(function(){
fixSidebarHeight();
})
$(window).load(function(){
fixSidebarHeight();
});
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script><script type="text/x-mathjax-config">MathJax.Hub.Config({TeX: { equationNumbers: { autoNumber: "AMS" } }});</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。