echo

when using 'echo' in function, why does result appear on previous line?

穿精又带淫゛_ 提交于 2020-01-11 13:02:37
问题 I wrote up a function that echoed out the id at the otherside of a linked table. when I write in the page that's calling the function-- echo "<br/>getalbumartistfunction: ".get_albumartistid($thisalbum); it returns the artist_id number on the line above where I have that function call. So I went into the function and switched it from 'echo' to 'return' and it now appears right after the colons like I would expect (and is probably more along the lines of what I need). So it works. But I am

when using 'echo' in function, why does result appear on previous line?

余生长醉 提交于 2020-01-11 13:01:02
问题 I wrote up a function that echoed out the id at the otherside of a linked table. when I write in the page that's calling the function-- echo "<br/>getalbumartistfunction: ".get_albumartistid($thisalbum); it returns the artist_id number on the line above where I have that function call. So I went into the function and switched it from 'echo' to 'return' and it now appears right after the colons like I would expect (and is probably more along the lines of what I need). So it works. But I am

Bash脚本15分钟进阶教程

本小妞迷上赌 提交于 2020-01-11 09:39:27
Bash脚本15分钟进阶教程 04/23. 2014 这里的技术技巧最初是来自谷歌的“Testing on the Toilet” (TOTT)。这里是一个修订和扩增版本。 脚本安全 我的所有bash脚本都以下面几句为开场白: #!/bin/bash set -o nounset set -o errexit 这样做会避免两种常见的问题: 引用未定义的变量(缺省值为“”) 执行失败的命令被忽略 需要注意的是,有些Linux命令的某些参数可以强制忽略发生的错误,例如“mkdir -p” 和 “rm -f”。 还要注意的是,在“errexit”模式下,虽然能有效的捕捉错误,但并不能捕捉全部失败的命令,在某些情况下,一些失败的命令是无法检测到的。(更多细节请参考这个帖子。) 脚本函数 在bash里你可以定义函数,它们就跟其它命令一样,可以随意的使用;它们能让你的脚本更具可读性: ExtractBashComments() { egrep "^#" } cat myscript.sh | ExtractBashComments | wc comments=$(ExtractBashComments < myscript.sh) 还有一些例子: SumLines() { # iterating over stdin - similar to awk local sum=0 local

shell传递参数-$的用法(三)

我只是一个虾纸丫 提交于 2020-01-11 07:27:23
$n:n代表一个数字,指执行脚本的第n个参数。特别地,$0指执行的文件名 [root@ipha-dev71-1 exercise_shell]# cat test.sh #!/bin/bash echo "shell 传递参数实例!" echo "执行的文件名:$0"; echo "第一个参数为:$1"; echo "第二个参数为:$2"; echo "第三个参数为:$3"; [root@ipha-dev71-1 exercise_shell]# ./test.sh 1 2 3 shell 传递参数实例! 执行的文件名:./test.sh 第一个参数为:1 第二个参数为:2 第三个参数为:3 $#:传递到脚本的参数个数 $*:以一个单字符串显示所有向脚本传递的参数 如 $1 $2 … $n [root@ipha-dev71-1 exercise_shell]# cat test.sh #!/bin/bash echo "shell 传递参数实例!" echo "第一个参数为:$1"; echo "参数个数为:$#"; echo "第二个参数为:$2"; echo "传递的参数作为一个字符串显示:$*"; [root@ipha-dev71-1 exercise_shell]# ./test.sh 1 2 3 shell 传递参数实例! 第一个参数为:1 参数个数为:3 第二个参数为

shell内建命令--Linux

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-11 06:50:16
exec命令()取代当前shell find ./ -name "*.txt" -exec ls -al {} \; find ./ -name "*.txt" -exec rm -rf {} \; [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-asuNPUtM-1577971154085)(en-resource://database/3994:1)] export 使变量都能被子shell识别 majun@instance-zqtg07w6:~$ cat export.sh #!/bin/bash echo $var majun@instance-zqtg07w6:~$ bash export.sh #输出空白 majun@instance-zqtg07w6:~$ var = 100 majun@instance-zqtg07w6:~$ bash export.sh #输出空白 majun@instance-zqtg07w6:~$ export var = 100 majun@instance-zqtg07w6:~$ bash export.sh 100 kill命令(常用) #kill的信号代码有很多种,常用的三种 1 ( 原地重启 ) 、9(强行杀掉)、15(正常结束) kill -9 2935 kill -1 2915 kill -15

getopts命令行参数处理

不问归期 提交于 2020-01-11 05:32:36
本文转载自: https://www.cnblogs.com/xiangzi888/archive/2012/04/03/2430736.html 作者:xiangzi888 转载请注明该声明。 一、getopts 简介   由于shell 命令行 的灵活性,自己编写代码判断时,复杂度会比较高。使用内部命令 getopts 可以很方便地处理命令行参数。一般格式为: getopts options variable   getopts 的设计目标是在循环中运行,每次执行循环,getopts 就检查下一个命令行参数,并判断它是否合法。即检查参数是否以 - 开头,后面跟一个包含在 options 中的字母。如果是,就把匹配的选项字母存在指定的变量 variable 中,并返回退出状态0;如果 - 后面的字母没有包含在 options 中,就在 variable 中存入一个 ? ,并返回退出状态0;如果命令行中已经没有参数,或者下一个参数不以 - 开头,就返回 不为0 的退出状态。 二、使用举例 cat args # !/bin/bash while getopts h:ms option do case " $option " in h) echo "option:h, value $OPTARG " echo "next arg index: $OPTIND ";; m) echo

shell脚本编程-计算方式

三世轮回 提交于 2020-01-11 04:09:35
Shell的几种计算方式 shell中只支持整数计算,也就是所有可能产生小数的运算都会舍去小数部分 支持常规算术运算符(+,-,*,/,%,**(幂运算))和复合算术运算符(+=,-=,*=,/=,%=)以及位运算(<<,>>,&,|,^,~)和自增自减(++,--)【操作对象只能是变量,不能是常数或表达式】 1. let 计算方式 # let "value=4<<2" # echo $value 16 2.$[]和$(())类似,用于简单的算术运算 # echo $[1+1] 2 # echo $[2-1] 1 3.expr计算方式 (特殊符号需要用转义字符,操作数和操作数之间需要有空格,否则就只会打印出字符串) # expr 1+1 1+1 # expr 1 + 1 2 # expr 2 \* 2 4 # rsult=$(expr 2 \* 2) # echo $rsult 4 4.内建运算命令declare (-i 指定变量为整型) # I=1+1 # echo $I 1+1 # declare -i J # J=1+1 # echo $J 2 5.算术扩展 为shell内置整数变量的运算机制,是shell内建命令之一 语法:$((算术表达式)) # i=2 # echo $((2*i+1)) 5# echo $((2*(i+1))) 6# var=$((2*i+2)) #

shell脚本

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-11 02:38:15
判断脚本:本例要求在虚拟机 server0 上创建 /root/foo.sh 脚本,任务目标如下 1)当运行/root/foo.sh redhat,输出为fedora 2)当运行/root/foo.sh fedora,输出为redhat 3)当没有任何参数或者参数不是 redhat 或者 fedora时,其错误输出产生以下信息: /root/foo.sh redhat|fedora #!/bin/bash #注释 if [ $ # -eq 0 ] ;then echo '/root/foo.sh redhat|fedora' > & 2 exit 1 elif [ $1 = redhat ] ; then echo 'fedora' elif [ $1 = fedora ] ; then echo 'redhat' else echo '/root/foo.sh redhat|fedora' > & 2 exit 2 fi 批量添加用户脚本:本例要求在虚拟机 server0 上创建 /root/batchusers 脚本,任务目标如下 1)此脚本要求提供用户名列表文件作为参数 2)如果没有提供参数,此脚本应该给出提示 Usage: /root/batchusers,退出并返回相应值 3)如果提供一个不存在的文件,此脚本应该给出提示 Input file not found

PHP7的新特性

别来无恙 提交于 2020-01-11 00:57:53
PHP7的新特性 性能测试 解压 tar -zxvf php-5.6.36.tar.gz tar -zxvf php-7.1.0.tar.gz tar -zxvf php-7.4.0.tar.gz 源码编译安装5.6.36 ./configure --prefix = /home/codes/php/php-5.6.36/ --enable-fpm --enable-debug make && make install 源码编译安装7.1.0 ./configure --prefix = /home/codes/php/php-7.1.0/ --enable-fpm --enable-debug make && make install 源码编译安装7.4.0 ./configure --prefix = /home/codes/php/php-7.4.0/ --enable-fpm --enable-debug make && make install 报错问题 报错:configure: error: Package requirements ( sqlite3 > 3.7.4 ) were not met: No package ‘sqlite3’ found 解决:yum install sqlite-devel 报错:configure: error: Package

nginx 自签名https

非 Y 不嫁゛ 提交于 2020-01-11 00:13:38
繁杂的命令,以下准备写好的sh,拷贝https.sh文件,设置执行权限:chmod u+x https.sh #!/bin/sh # create self-signed server certificate: read -p "Enter your domain [www.example.com]: " DOMAIN echo "Create server key..." openssl genrsa -des3 -out $DOMAIN.key 1024 echo "Create server certificate signing request..." SUBJECT="/C=US/ST=Mars/L=iTranswarp/O=iTranswarp/OU=iTranswarp/CN=$DOMAIN" openssl req -new -subj $SUBJECT -key $DOMAIN.key -out $DOMAIN.csr echo "Remove password..." mv $DOMAIN.key $DOMAIN.origin.key openssl rsa -in $DOMAIN.origin.key -out $DOMAIN.key echo "Sign SSL certificate..." openssl x509 -req -days 3650 -in