我一直在寻找解释.以下是apt-fast.sh脚本的一个真实示例:
if [ ! -x /usr/bin/axel ]
then echo "axel is not installed, perform this?(y/n)"
read ops
case $ops in
y) if apt-get install axel -y --force-yes
then echo "axel installed"
else echo "unable to install the axel. you are using sudo?" ; exit
fi ;;
n) echo "not possible usage apt-fast" ; exit ;;
esac
fi
Run Code Online (Sandbox Code Playgroud)
"fi ;;"在if街区中间有什么用?
每次循环执行时都可以回显吗?例如:
foreach(range(1,9) as $n){
echo $n."\n";
sleep(1);
}
Run Code Online (Sandbox Code Playgroud)
我不想在循环结束时打印所有内容,而是希望每次打印每个结果.
有关如何解压缩管道zip文件的任何想法,如下所示:
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip
Run Code Online (Sandbox Code Playgroud)
我希望将文件解压缩到一个目录,就像我们以前使用普通文件一样:
wget -qO- http://downloads.wordpress.org/plugin/akismet.2.5.3.zip | unzip -d ~/Desktop
Run Code Online (Sandbox Code Playgroud) 删除文本字符串的第一行然后在PHP中回显其余内容的最佳方法是什么?
例如.
这是文本字符串:
$t=<<<EOF
First line to be removed
All the rest
Must remain
EOF;
Run Code Online (Sandbox Code Playgroud)
这是最终输出:
All the rest
Must remain
Run Code Online (Sandbox Code Playgroud)
如果我正在使用Bash中的文件,我可以轻松地完成下一个:
sed -i~ 1d target-file
要么:
tail -n +2 source-file > target-file
有任何想法吗?
我正在编写一个bash脚本(用于基于apt-get的OS),它可以自动执行各种程序的安装过程.在这个过程中,我有时会运行"apt-get -fy update"和"apt-get -fy upgrade".在升级过程中,偶尔需要重启.
我的问题:有没有办法测试系统是否在运行"apt-get -fy upgrade"后要求重启?我正在尝试编写脚本,使其从头到尾运行,无需任何干预.
谢谢.
我在PDF文档的每个页面上都有一个包含此字符串的行:
%REPLACE%
我想找到并替换另一个字符串.
有谁知道如何使用PDFTK等命令行应用程序执行此操作?
这种民间给了我一个重要的线索,但是我想的东西更直接.
谢谢.
我想阅读文件"teste",做一些"查找和替换"并用结果覆盖"teste".我到现在越接近:
$cat teste
I have to find something
This is hard to find...
Find it wright now!
$sed -n 's/find/replace/w teste1' teste
$cat teste1
I have to replace something
This is hard to replace...
Run Code Online (Sandbox Code Playgroud)
如果我尝试像这样保存到同一个文件:
$sed -n 's/find/replace/w teste' teste
Run Code Online (Sandbox Code Playgroud)
要么:
$sed -n 's/find/replace/' teste > teste
Run Code Online (Sandbox Code Playgroud)
结果将是一个空白文件...
我知道我错过了一些非常愚蠢的东西,但欢迎任何帮助.
更新:根据人们提供的提示和这个链接:http://idolinux.blogspot.com/2008/08/sed-in-place-edit.html这里是我的更新代码:
sed -i -e 's/find/replace/g' teste
Run Code Online (Sandbox Code Playgroud) 如何使用Bash脚本从wordpress 中将变量$ SALT的内容插入文件的特定点(行或字符串),如wp-contet.php?
SALT=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/)
Run Code Online (Sandbox Code Playgroud) 我想给一个关键字,找到这个关键字在文件中的行,并删除整行.
这是我得到的,但它不能正常工作:
KEYWORD='domain.com'
cat /etc/hosts | grep -v "$KEYWORD" > /etc/hosts
Run Code Online (Sandbox Code Playgroud)
UPDATE
这对我有用:
sed -i_bak -e '/domain\.com/d' /etc/hosts
但是,由于我有两行"domain.com",有没有办法告诉sed只擦除确切关键字"domain.com"出现的行
这是/ etc/hosts的原始内容:
127.0.0.1 localhost localhost.localdomain
222.111.22.222 hvn.domain.com
222.111.22.222 domain.com
Run Code Online (Sandbox Code Playgroud)
以下是命令后的结果sed -i_bak -e '/domain\.com/d' /etc/hosts:
127.0.0.1 localhost localhost.localdomain
Run Code Online (Sandbox Code Playgroud)
我试过sed -i_bak -e '/\<namourphoto\.com\.br\>/d' ~/Desktop/hosts但它没用.
结论
这是我提出的代码(基于优秀人员给我的帮助):
D=domain.com
DOMAIN=`echo "$D" | sed 's/\./\\\\./g'`
sed -i_bak -e "/[\t]$DOMAIN/d" /etc/hosts
Run Code Online (Sandbox Code Playgroud)
注意:
我指望在删除域名之前总是有一个标签
我正在自动逃避域名的点.
我需要将HTML转换为等效的Markdown结构化文本.
由于我使用PHP编程,有些人表示Markdownify可以完成这项工作,但不幸的是,代码没有更新,实际上它没有用.在sourceforge.net/projects/markdownify有一个"注意:不支持 - 你想维护这个项目吗?联系我!Markdownify是一个用PHP编写的HTML到Markdown转换器.看它是html2text.php的继承者,因为它有更好的设计,更好的性能和更少的角落情况."
根据我的发现,我只有两个不错的选择:
Python:Aaron Swartz的html2text.py
Ruby:Singpolyma的html2markdown.rb,基于Nokogiri
所以,从PHP,我需要传递HTML代码,调用Ruby/Python脚本并接收输出.
(顺便说一句,一个民众在这里提出了一个类似的问题("如何从php调用ruby脚本?"),但我的案例没有实用信息).
按照Tin Man的提示(下图),我得到了这个:
PHP代码:
$t='<p><b>Hello</b><i>world!</i></p>';
$scaped=preg_quote($t,"/");
$program='python html2md.py';
//exec($program.' '.$scaped,$n); print_r($n); exit; //Works!!!
$input=$t;
$descriptorspec=array(
array('pipe','r'),//stdin is a pipe that the child will read from
array('pipe','w'),//stdout is a pipe that the child will write to
array('file','./error-output.txt','a')//stderr is a file to write to
);
$process=proc_open($program,$descriptorspec,$pipes);
if(is_resource($process)){
fwrite($pipes[0],$input);
fclose($pipes[0]);
$r=stream_get_contents($pipes[1]);
fclose($pipes[1]);
$return_value=proc_close($process);
echo "command returned $return_value\n";
print_r($pipes);
print_r($r);
}
Run Code Online (Sandbox Code Playgroud)
Python代码:
#! /usr/bin/env python
import html2text
import …Run Code Online (Sandbox Code Playgroud)