cat

Shell编程—创建函数

安稳与你 提交于 2019-12-15 20:28:49
1 基本的脚本函数 函数是一个脚本代码块,你可以为其命名并在代码中任何位置重用。要在脚本中使用该代码块时,只要使用所起的函数名就行了。 1.1 创建函数 有两种格式可以用来在bash shell脚本中创建函数。第一种格式采用关键字function,后跟分配给该代码块的函数名。 function name { commands } 二种格式更接近于其他编程语言中定义函数的方式。 name() { commands } 1.2 使用函数 $ cat test1 #!/bin/bash # using a function in a script function func1 { echo "This is an example of a function" } count=1 while [ $count -le 5 ] do func1 count=$[ $count + 1 ] done echo "This is the end of the loop" func1 echo "Now this is the end of the script" $ ./test1 This is an example of a function This is an example of a function This is an example of a function This is

Shell编程—呈现数据

三世轮回 提交于 2019-12-15 20:04:09
1. 标准文件描述符 Linux用文件描述符(file descriptor)来标识每个文件对象。文件描述符是一个非负整数,可以唯一标识会话中打开的文件。每个进程一次 多可以有九个文件描述符。出于特殊目的,bash shell保留了前三个文件描述符(0、1和2): 文件描述符 缩 写 描 述 0 STDIN 标准输入 1 STDOUT 标准输出 2 STDERR 标准错误 1. STDIN : 代表shell的标准输入。对终端界面来说,标准输入是键盘。 2. STDOUT : STDOUT文件描述符代表shell的标准输出。在终端界面上,标准输出就是终端显示器。 3. STDERR : STDERR文件描述符处理错误消息。STDERR文件描述符代表shell的标准错误输出。 1.1 重定向错误 1. 只重定向错误 $ ls -al test badtest test2 2> test5 -rw-rw-r-- 1 rich rich 158 2014-10-16 11:32 test2 $ cat test5 ls: cannot access test: No such file or directory ls: cannot access badtest: No such file or directory 2. 重定向错误和数据 $ ls -al test test2

centos的基本信息和ssh

烈酒焚心 提交于 2019-12-14 21:51:56
centos的基本信息 ** Centos(Community Enterprise Operating System,中文意思是社区企业操作系统)是Linux发行版之一,它是来自于Red Hat Enterprise Linux依照开放源代码规定释出的源代码编译而成。由于出自同样的源代码,因此有些要求高度稳定性的服务器用CentOs替代商业版的Red Hat Enterprise Linux使用。两者的不同在于CentOs完全开源。 1.查看内核版本命令: [root@iZbp1emchz7p3l08noq6cvZ ~]# cat /proc/version [root@iZbp1emchz7p3l08noq6cvZ ~]# uname -r [root@iZbp1emchz7p3l08noq6cvZ ~]# uname -a 2.查看linux版本 [root@test02 ~]# cat /etc/redhat-release 3.查看 linux cpu型号 核数 [root@iZbp1emchz7p3l08noq6cvZ ~]# cat /proc/cpuinfo |grep “model name” && cat /proc/cpuinfo |grep “physical 😕/img-blog.csdnimg.cn/20191214184331253.png)” 4

简明易懂的call apply

ぐ巨炮叔叔 提交于 2019-12-14 17:13:56
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 在iteye看到一篇对call解释得相当简明易懂,觉得得宣传一下 : http://uule.iteye.com/blog/1158829 一、方法的定义 call方法: 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象。 说明: call 方法可以用来代替另一个对象调用一个方法。call 方法可将一个函数的对象上下文从初始的上下文改变为由 thisObj 指定的新对象。 如果没有提供 thisObj 参数,那么 Global 对象被用作 thisObj。 apply方法: 语法:apply([thisObj[,argArray]]) 定义:应用某一对象的一个方法,用另一个对象替换当前对象。 说明: 如果 argArray 不是一个有效的数组或者不是 arguments 对象,那么将导致一个 TypeError。 如果没有提供 argArray 和 thisObj 任何一个参数,那么 Global 对象将被用作 thisObj, 并且无法被传递任何参数。 2、常用实例 a例 function add(a,b) { alert(a+b); }function sub(a,b) { alert(a-b); } add

PHP performance file_get_contents() vs readfile() and cat

本小妞迷上赌 提交于 2019-12-14 01:46:09
问题 I am doing some benchmarking with PHP file reading functions just for my overall knowledge. So I tested three different ways to read the whole content of a file that I thought would be very fast. file_get_contents() well-know for its very high performance readfile() known to be a very good alternative to file_get_contents() when it comes to outputting the data directly to stdout exec('cat filename') one very handy and fast UNIX command So here is my benchmarking code, note that I enabled the

Android Studio - logcat

喜欢而已 提交于 2019-12-13 10:39:44
问题 Can someone tell me what is wrong with my app it crashes on statr . Here is the LogCat: Process: com.moneyegg.bdpsoft.makemonepaypal, PID: 3358 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.moneyegg.bdpsoft.makemonepaypal/com.moneyegg.bdpsoft.makemonepaypal.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class uses-permission at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325) at android.app

Linux Shell 文本处理工具集锦

杀马特。学长 韩版系。学妹 提交于 2019-12-13 07:42:24
来自:me115, www.cnblogs.com/me115/p/3427319.html 本文将介绍Linux下使用Shell处理文本时最常用的工具: find、grep、xargs、sort、uniq、tr、cut、paste、wc、sed、awk; 提供的例子和参数都是最常用和最为实用的; 我对shell脚本使用的原则是命令单行书写,尽量不要超过2行; 如果有更为复杂的任务需求,还是考虑python吧; find 文件查找 查找txt和pdf文件 find . \ ( -name "*.txt" -o -name "*.pdf" \ ) -print 正则方式查找.txt和pdf find . -regex ".*\(\.txt|\.pdf\)$" -iregex:忽略大小写的正则 否定参数 查找所有非txt文本 find . ! -name "*.txt" -print 指定搜索深度 打印出当前目录的文件(深度为1) find . -maxdepth 1 -type f 定制搜索 按类型搜索: find . -type d -print //只列出所有目录 -type f 文件 / l 符号链接 按时间搜索: -atime 访问时间 (单位是天,分钟单位则是-amin,以下类似) -mtime 修改时间 (内容被修改) -ctime 变化时间 (元数据或权限变化)

Correct syntax and usage of `cat` command?

自古美人都是妖i 提交于 2019-12-13 04:17:17
问题 (This question is a follow-up on this comment, in an answer about git hooks) I'm far too unskilled in bash (so far) to understand fully the remark and how to act accordingly. More specifically, I've been advised to avoid using bash command cat this way : echo "$current_branch" $(cat "$1") > "$1" because the order of operations depends on the specific shell and it could end up destroying the contents of the passed argument, so the commit message itself if I got it right? Also, how to "save the

eval cat inside a function

北慕城南 提交于 2019-12-13 02:59:25
问题 I've been trying to evaulate an expression inside a function as follows: eval "fn() { $(cat fn.sh); }" Where fn.sh contains the following: #!/bin/sh echo "You provided $1." So that when I call: fn "a phrase"` it prints "You provided a phrase.". However I cannot get it to work. What's particularly frustrating is that: eval "$(cat fn.sh)" works perfectly! What am I missing here? What I've tried: eval "fn() { \"\$(cat fn.sh)\"; }" fn # bash: #!/bin/sh # echo "You provided $1." # return 1: No

Howto enqueue all files listed in a file to a vlc playlist using cat and awk

こ雲淡風輕ζ 提交于 2019-12-12 14:22:35
问题 I'm trying to enqueue all files listed in a textfile to a VLC playlist. Every line holds an absolute path to a movie file. Adding just one file to the playlist works perfectly: vlc --playlist-enqueue someMediaFile I'm also able to execute a command (e.g. print) for every line listed in the textfile using cat and awk like this: cat avis.txt | awk '{print $0}' ... But combined, it doesn't work: cat avis.txt | awk '{vlc --playlist-enqueue $0}' The line above prints the content of the file avis