cat

SHELL学习笔记三

这一生的挚爱 提交于 2019-12-02 06:05:38
SHELL学习笔记三 SHELL学习笔记一 SHELL学习笔记二 SHELL学习笔记三 for 命令 for var in list do commands done $ cat test1 #!/bin/bash # basic for command for test in Alabama Alaska Arizona Arkansas California Colorado do echo The next state is $test done $ ./test1 The next state is Alabama The next state is Alaska The next state is Arizona The next state is Arkansas The next state is California The next state is Colorado $ 读取列表中的复杂值 使用转义字符(反斜线)来将单引号转义; 使用双引号来定义用到单引号的值。 $ cat test2 #!/bin/bash # another example of how not to use the for command for test in I don\'t know if "this'll" work do echo "word:$test" done $ .

shell 之 数组

有些话、适合烂在心里 提交于 2019-12-02 03:31:11
函数传参使用场景示例,需求描述:写一个脚本,实现nginx服务的启动、停止、重启。 [root@shell day06]# cat nginx.sh #!/bin/bash source /etc/init.d/functions if [ $# -ne 1 ];then echo "Usage: $0 {start|stop|status|reload|restart}" exit fi rc=$1 retu() { if [ $? -eq 0 ];then action "Nginx is $rc 成功!" /bin/true else action "Nginx is $rc 失败!" /bin/false fi } start() { if [ ! -f /var/run/nginx.pid ];then /usr/sbin/nginx retu else echo "Nginx 服务正在运行....." fi } stop() { if [ -f /var/run/nginx.pid ];then /usr/sbin/nginx -s stop retu else echo "Nginx 服务不在运行......" fi } reload() { if [ -f /var/run/nginx.pid ];then /usr/sbin/nginx -s reload

shell 流程控制

时光总嘲笑我的痴心妄想 提交于 2019-12-02 02:01:03
场景实践二:查看磁盘/分区当前使用状态,如果使用率超过80%则报警发邮件 [root@shell shell]# cat disk.sh #!/bin/bash #定义变量 Disk_Use=$(df -h |awk '/\/$/{print $(NF-1)}') #根据磁盘的使用率情况进行判断 if [ ${Disk_Use/\%/} -gt 7 ];then echo "当前主机$(hostname) 磁盘根分区使用率不正常,使用率为:$Disk_Use" else echo "当前主机$(hostname) 磁盘根分区使用率正常,使用率为:$Disk_Use" fi [root@shell shell]# cat disk.sh #!/bin/bash #定义变量 [ -f /etc/init.d/functions ] && source /etc/init.d/functions Disk_Use=$(df -h |awk '/\/$/{print $(NF-1)}') #根据磁盘的使用率情况进行判断 if [ ${Disk_Use/\%/} -gt 80 ];then action "当前主机$(hostname) 磁盘根分区使用率不正常,使用率为:$Disk_Use" /bin/false else action "当前主机$(hostname) 磁盘根分区使用率正常

第二章 Shell变量定义

馋奶兔 提交于 2019-12-02 01:47:06
1. Shell变量概述 1. 什么是变量 变量是Shell传递数据的一种方法,简单理解:用一个固定的字符串去表示不固定的内容,便于后续引用。 2.变量命令规范 变量定义时名称有要求:字母、数字、下划线几个组成,尽量字母开头,变量名最好具备一定的含义。 ip=10.0.0.100 ip1=10.0.0.100 Hostname_Ip=10.0.0.100 hostname_IP=10.0.0.100 等号是赋值,需要注意:等号两边不能有空格,其次定义的变量不要与系统命令出现冲突。 3. Shell变量定义的方式 01)用户自定义变量:人为定义的变量名称。 02)系统环境变量:保存的是和系统操作环境相关的数据。 03)位置参数变量:向脚本中进行参数传递,变量名不能自定义,变量作用是固定的。 04)预定义的变量:是bash中已经定义好的变量,变量名不能自定义,变量作用也是固定的。 4. Shell变量定义实践 01.用户自定义变量示例,当前Shell有效 #1.定义变量,变量名=变量值。不能出现"-横岗"命令 #定义变量有空格时,必须使用引号 [root@cc ~]# cc="hello shell" #2.引用变量,$变量名 或 ${变量名} [root@cc ~]# echo $cc hello shell [root@cc ~]# echo $cc_test [root@cc ~

Linux下Shell入门

落爺英雄遲暮 提交于 2019-12-01 23:58:00
Shell是人和计算机之间交流的''翻译官'',通过Shell终端解释器,可以访问到系统内核的服务,Shell执行需要脚本解释器,以及一个编写脚本的工具,一般解释器使用/bin/bash,脚本工具使用vim。Shell跟其他编程语言一样,也支持参数和变量、流程控制、分支等特性,下面简单了解一下。 脚本解释器 通过cat /etc/shells可以查看系统提供的shell脚本解释器,通过echo $SHELL命令可以查看当前默认使用的解释器,可以看出默认情况下是用/bin/bash。 # 查看提供的[root@node01 /home/yangchaolin/hehe]# cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/dash /bin/tcsh /bin/csh# 查看默认使用的 [root@node01 /home/yangchaolin/hehe]# echo $SHELL /bin/bash 第一个Shell脚本 下面写一个输出"hello world"的脚本,来完成第一个shell脚本。 # vim命令进入脚本编辑[root@node01 /home/yangchaolin/shell]# vim shell01.sh# 编辑完查看 [root@node01 /home/yangchaolin/shell]#

linux cat 文件编码

妖精的绣舞 提交于 2019-12-01 21:48:34
test.log是utf-16的编码 cat test.log会报错 但是我们可以cat的时候指定编码格式 iconv -f 文件编码 -t 终端编码 input.log iconv -f utf-16 -t utf-8 test.log 来源: https://www.cnblogs.com/ruiy/p/11717780.html

Using “cat” to write non-English characters into a .html file (in R)

拜拜、爱过 提交于 2019-12-01 21:09:43
Here is the code showing the problem: myPath = getwd() cat("abcd", append = T, file =paste(myPath,"temp1.html", sep = "\\")) # This is fine cat("<BR/><BR/><BR/>", append = T, file =paste(myPath,"temp1.html", sep = "\\")) # This is fine cat("שלום", append = F, file =paste(myPath,"temp1.html", sep = "\\")) # This text gets garbled when the html is opened using google chrome on windows 7. cat("שלום", append = F, file =paste(myPath,"temp1.txt", sep = "\\")) # but if I open this file in a text editor - the text looks fine # The text in the HTML folder would look as if I where to run this in R: (x <

grep/regex can't find accented word

谁说胖子不能爱 提交于 2019-12-01 19:53:26
I'm trying mount a regex that get some words on a file where all letters of this word match with a word pattern. My problem is, the regex can't find accented words, but in my text file there are alot of accented words. My command line is: cat input/words.txt | grep '^[éra]\{1,4\}$' > output/words_era.txt cat input/words.txt | grep '^[carroça]\{1,7\}$' > output/words_carroca.txt And the content of file is: carroça éra éssa roça roco rato onça orça roca How can I fix it? If your file is encoded in ISO-8859-1 but your system locale is UTF-8, this will not work. Either convert the file to UTF-8 or

《驱动调试 - 调试信息打印到proc虚拟文件》

半腔热情 提交于 2019-12-01 19:21:28
printk() 会将打印信息存在内核的环形缓冲区 log_buf[] 里, 可以 通过dmesg命令来查看log_buf[] 1.环形缓冲区log_buf[]又是存在内核的哪个文件呢? 位于 /proc/kmsg 里,所以除了 dmesg 命令查看,也可以使用 cat /proc/kmsg 来查看。 2. 但是,dmesg 命令和cat /proc/kmsg 有所不同 2.1 dmesg命令 每次使用,都会打印出环形缓冲区的所有信息。 2.2 cat /proc/kmsg 只会打印出每次新的环形缓冲区的信息。 比如,第一次使用cat /proc/kmsg,会打印出内核启动的所有信息。 第二次使用cat /proc/kmsg,就不会出现之前打印的信息,只打印继上次使用cat /proc/kmsg之后的新的信息,比如下图所示: 3. 接下来我们便进入内核, 找/proc/kmsg 文件在哪生成的 搜索"kmsg",找到位于fs\proc\proc_misc.c 文件的proc_misc_init()函数中, 来源: https://www.cnblogs.com/zhuangquan/p/11714143.html

Bash - how to preserve newline in sed command output?

[亡魂溺海] 提交于 2019-12-01 18:22:21
Assuming I have a file BookDB.txt which stores data in the following format : Harry Potter - The Half Blood Prince:J.K Rowling:40.30:10:50 The little Red Riding Hood:Dan Lin:40.80:20:10 Harry Potter - The Phoniex:J.K Rowling:50.00:30:20 Harry Potter - The Deathly Hollow:Dan Lin:55.00:33:790 Little Prince:The Prince:15.00:188:9 Lord of The Ring:Johnny Dept:56.80:100:38 Three Little Pig:Andrew Lim:89.10:290:189 All About Linux:Ubuntu Team:76.00:44:144 Catch Me If You Can:Mary Ann:23.60:6:2 Python for dummies:Jared Loo:15.99:1:10 I am trying to replace the (:) delimiter with (, ) in my output. It