bash脚本

以下是为您整理出来关于【bash脚本】合集内容,如果觉得还不错,请帮忙转发推荐。

【bash脚本】技术教程文章

linux – 使用简单的Bash脚本提供帮助【代码】

我正在尝试编写我的第一个Bash脚本.我正在尝试创建一个脚本来启动我的主要流浪汉VM,以便我可以从任何目录启动它.这是我到目前为止:#!/bin/bash if [[ -n "$1" ]]; then if [["$1" == "up"]];then cd /home/user/DevEnv && vagrant up;elif [["$1" == "halt"]];then cd /home/user/DevEnv && vagrant halt;fi else echo "Must pass up or halt to script"; fi当我运行这个时,我得到以下输出user@Debian ~ $dev Must pass up or hal...

linux – 显示文件权限的bash脚本提供了错误的输出【代码】

我正在学习bash,并希望你们能用以下脚本帮我解决发生的事情#!/bin/bash#primer if if [ -f $file1 ]; thenecho "file1 is a file" elseecho "file1 is not a regular file" fi #segundo if if [ -r $file1 ]; thenecho "file1 has read permission" elseecho "file1 doesnot have read permission" fi #tercer if if [ -w $file1 ]; thenecho "file1 has write permission" elseecho "file1 doesnot have write permission" fi #cu...

linux – 将bash脚本的输出写入带有日期的文件【代码】

我正在尝试创建一个与数据一起运行的bash脚本的日志文件.我目前有这个:bash script.sh > /var/log/%Y-%m-%d_%H:%M.log问题是日志文件实际写入%Y-%m-%d_%H:%M而不是日期.是否有办法通过仅在控制台中运行日期来实际写出日期?解决方法:将该字符串传递给日期:bash script.sh > "/var/log/$(date +%Y-%m-%d_%H:%M).log"

linux – Bash脚本中的Sed – 替换可变内容的错误原因【代码】

我有一个Bash脚本:var=" <Location /webdav/vendor1>DAV OnAuthType DigestAuthName "rw"AuthUserFile /etc/password/digest-passwordRequire user test123456 </Location><Location /webdav/limited/vendor1/demo>Dav OnAuthType DigestAuthName "ro"AuthUserFile /etc/password/digest-password-test2 <LimitExcept GET HEAD OPTIONS PROPFIND> deny from all </LimitExcept> </Location> "sed -i -e "s/somestringX/${var}/g"...

linux – bash脚本中的[…]代表什么?【代码】

我正在阅读this教程,我遇到了bash脚本使用[…]作为外卡字符.那么究竟什么[…]站在bash脚本中?解决方法:它是一种正则表达式的字符匹配语法;从Bash Reference Manual,§3.5.8.1 (Pattern Matching):[...] Matches any one of the enclosed characters. A pair of characters separated by a hyphen denotes a range expression; any character that sorts between those two characters, inclusive, using the current locale’s co...

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脚本循环包含域的文本文件【代码】

嘿伙计们,我写了一个脚本,读取网页的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脚本中的错误替换错误【代码】

我已经尝试了很多,但无法从中获得解决方案.我有一个简单的脚本:#! /bin/sh o="12345" a=o b=${!a} echo ${a} echo ${b}执行时如$. scp.sh它生成正确的输出而没有错误,但执行时如:$./scp.sh它产生./scp.sh: 4: ./scp.sh: Bad substitution任何想法为什么会这样. 我被建议使用bash模式,它工作正常.但是当我通过Python执行相同的脚本(将脚本标题更改为bash)时,我得到了同样的错误. 我是用Python调用的:import os os.system(". ./sc...

linux – bash脚本逐行读取和echo到文件【代码】

我不能让这个脚本做我想做的事.有人可以帮助它应该逐行读取文本文件,然后将结果回显到另一个文件中.但它没有认识到空白行.因为它应该打印线,除非它是空白然后它打算打印到文件.iname = checktest while read line do if [ "$line" == "" ]; thenecho "<blank>" >> $iname2.txtelse echo "$line" >> $iname2.txt fidone <$iname.txt解决方法:bash中的变量赋值之间不能有空格.#!/bin/bashiname=checktest #Should b...