【关于CentOS下Linux的bash 漏洞,查看和解决的方法】教程文章相关的互联网学习教程文章

linux – 如果bash中的语句错误【代码】

参见英文答案 > How do I compare two string variables in an ‘if’ statement in Bash? 12个 i=0 for f in `awk '{print $1}' config.list` doecho "i value is $i"if ["$i" = "0"]thenecho "here"i=$((i+1))continue fiarr[i]=$f i=$((i+1)) done在上面的bash脚本中,我收到一个错误,我使用了if语句,看起来像这样./script.sh: line 5: [0: command not found请指出我可能是我的错误.解决方...

linux – Bash – 重命名多个文件扩展名【代码】

我刚刚切换到Linux,我想更改一堆文件以具有不同的扩展名.例如,我想将.doc / docx更改为.txt,将图像更改为.jpg等等.是否有一个csh脚本可以覆盖任何扩展名,或者我是否必须为每个文件类型编写一个新脚本. 到目前为止我有这个,但我不确定它是否真的有效.任何帮助深表感谢!#!/bin/bash for f in *.$1 do[ -f "$f" ] && mv -v "$f" "${f%$1}$2" done解决方法:那会重命名;请记住,重命名Word文档不会导致它成为文本.

linux – 如何编译bash?【代码】

如何编译bash?我对从http://ftp.gnu.org/gnu/bash/bash-4.2.tar.gz获得的代码做了一些小修改.我希望看到这些更改.谁能指点我编写bash的简单步骤?解决方法:你可以先跑cd bash-4.2./configure --prefix=/usr --bindir=/bin --htmldir=/usr/share/doc/bash-4.2 --without-bash-malloc --with-installed-readlinemakemake install有关更多信息...

linux – 在bash中重用命令管道【代码】

我使用以下内容来缩进configure脚本的输出:./configure | sed "s/^/ /"现在我想重用管道后面的部分,所以我不必写./configure | sed "s/^/ /" make | sed "s/^/ /" make install | sed "s/^/ /"我试图将sed放在这样的变量中:indent=sed "s/^/ /"然后呢./configure | indent但那不起作用 – 我怎样才能做到这一点?解决方法:使用BASH数组来保存sed命令:indent=(sed "s/^/ /")然后使用:./configure | "${indent...

linux – Bash – 计算字符串中的子串【代码】

我有点想写一个命令来计算一个字符串出现在字符串中的次数. 我宁愿先计运算符字符串出现的次数,并根据其结果调整“for”,而不是运行10次以下的代码: 在这里你可以看到代码:CommandResult="Interface Chipset Driver mon0 Unknown iwlwifi - [phy0]wlan0 Unknown iwlwifi - [phy0]"for i in `seq 0 9`; doInstanceID="mon"$iif echo "$CommandResult" | grep -q "$InstanceID"; thenecho "found"fi ...

linux – 在bash命令中,#:*!#:1-是什么意思?【代码】

在下面的Bash命令中,含义是什么:!#:*!#:1echo "This is a sentence." !#:* !#:1- >text3解决方法:它使用的是bash’s history substitution mechanism. 具体来说,!#指的是当前行(最多但不包括!#本身的位置). !#:*是命令名后该行的一部分(因此,在这种情况下,“这是一个句子.”). !#:1-与!#:*相同,只是它省略了最后一个单词(因此它不包括我们刚刚通过!#:*添加的“这是一个句子”的第二个副本). 最终的结果是一行三个副...

linux – 如何在bash脚本的循环中使用参数运行curl命令?【代码】

参见英文答案 > Difference between single and double quotes in Bash 6个我有一个curl命令,我想在for循环中执行.例如,我想循环1-100次,当curl命令运行时,它在curl命令本身中使用iterator变量值.就像是#!/bin/bashfor i in {1..10}docurl -s -k 'GET' -H 'header info' -b 'stuff' 'http://example.com/id=$i' done--notice here I want var i to be changing with every curl.一切都有...

linux – 同时读取bash数组(不进入)【代码】

我试图在读取时使用数组,但整个数组立即输出.#!/bin/bashdeclare -a arr=('1:one' '2:two' '3:three');while read -e it ; doecho $it done <<< ${arr[@]}它应该单独输出每个值(但不是),所以也许在读取时不是热门票?解决方法:对于这种情况,使用for循环更容易:$declare -a arr=('1:one' '2:two' '3:three') $for it in "${arr[@]}"; do echo $it; done 1:one 2:two 3:threewhile读取方法非常有用(a)当您想要从文件中读取数据时,以...

linux – Bash – 从一个文件中删除行,同时迭代另一个文件中的行【代码】

我有两个文件. file.txt和delete.txt file.txt包含以下内容:/somedirectory/ /somedirectory2/somefile.txt /anotherfile.txtdelete.txt包含:/somedirectory/ /somedirectory2/somefile.txt我需要删除delete.txt中包含的file.txt中的行 cat file.txt应该导致:/anotherfile.txt到目前为止,我已经尝试过这个没有运气:while read p; doline=$p;sed -i '/${line}/d' file.txt; done < delete.txt我没有收到任何错误,它只是不编辑我...

linux – 如何在bash shell脚本中正确处理通配符扩展?【代码】

#!/bin/bashhello() {SRC=$1DEST=$2for IP in `cat /opt/ankit/configs/machine.configs` ; doecho $SRC | grep '*' > /dev/nullif test `echo $?` -eq 0 ; thenfor STAR in $SRC ; doecho -en "$IP"echo -en "\n\t ARG1=$STAR ARG2=$2\n\n"doneelseecho -en "$IP"echo -en "\n\t ARG1=$SRC ARG2=$DEST\n\n"fidone }hello $1 $2以上是我提供的shell脚本(SRC)& desitnation(DEST)路径.当我没有放入带有外卡的SRC路径时,它工作正常.当...

linux – bash:一次获取多个数组元素的简单方法?【代码】

是否有* nix命令格式化输入(由换行符分隔),以便每行只显示特定的最大元素数?例如:$yes x | head -10 | command 4 x x x x x x x x x x我写了一个执行此任务的快速bash脚本(如下所示),但它似乎很长并且可能效率低下.有一个更好的方法吗?#!/bin/shif [ -z "$1" -o -z "$2" ]; thenecho Usage `basename $0` {rows} {columns}exit 1 fiROWS=$1 COLS=$2input=$(yes x | head -${ROWS}) lines=() i=0 j=0 eol=0for x in ${input[*]} ...

linux – 使用bash脚本循环包含域的文本文件【代码】

嘿伙计们,我写了一个脚本,读取网页的href标签,并获取该网页上的链接,并将它们写入文本文件.现在我有一个包含这些链接的文本文件,例如:http://news.bbc.co.uk/2/hi/health/default.stm http://news.bbc.co.uk/weather/ http://news.bbc.co.uk/weather/forecast/8?area=London http://newsvote.bbc.co.uk/1/shared/fds/hi/business/market_data/overview/default.stm http://purl.org/dc/terms/ http://static.bbci.co.uk/bbcdotcom...

linux – grep输出只打印bash脚本中的单行【代码】

参见英文答案 > I just assigned a variable, but echo $variable shows something else 6个如何从grep中获取结果以在bash脚本中自行打印? 在终端中使用grep时,输出会显示我希望它出现的方式. 例如:$whois x.x.85.72 | grep 'OrgName\|NetRange\|inetnum\|IPv4' NetRange: x.x.85.64 - x.x.85.95 NetRange: x.x.0.0 - x.x.255.255 OrgName: xxxxx Technologies Inc.在bas...

linux – 在BASH中字符串结尾之前插入一个字符4个字符【代码】

有没有办法在字符串结尾之前插入冒号4个字符?例如,我有0x2aab3f439000,我需要0x2aab3f43:9000 谢谢解决方法:使用sed你可以做到:s='0x2aab3f439000' sed 's/.\{4\}$/:&/' <<< "$s" 0x2aab3f43:9000

检查文件是否存在Linux bash【代码】

所以我正在尝试检查文件是否存在,然后脚本应该执行某些操作.我遇到的问题实际上是让它认识到某些东西确实存在.if [ -e /temp/file.txt ]; thenecho "file found!"sudo cp -r temp/* extra elseecho "file not found! Creating new one..."./create.sh fi下面是我正在测试的目录中的文件示例.它们显然存在,但由于某种原因,我无法让脚本看到它.我究竟做错了什么?nima@mkt:/docs/text$ls -a temp . .. more file.txt file2.txt解...