假设您有以下脚本:
# My comment line 1
# My comment line 2
# My comment line 3
echo "My script"
cd $MY_PATH
./anotherScript.ksh
Run Code Online (Sandbox Code Playgroud)
是否有任何命令可以显示:
# My comment line 1
# My comment line 2
# My comment line 3
Run Code Online (Sandbox Code Playgroud)
或者,我可以编写一个脚本来检测第一块注释。
谢谢
有没有办法将数据嵌入到 perl 脚本中,然后以类似于 c-shell 的方式作为临时文件使用/读取它。
cat<< eof>tmp.txt
store a multiline text file
eof
run_some_function on [anotherexternalfile] with [tmp.txt]
rm tmp.txt
Run Code Online (Sandbox Code Playgroud)
我想在一个 perl 脚本中嵌入多组命令/数据文件来包装一组命令,以避免需要过多的外部命令文件。
更新
嵌入的文件/数据需要作为另一个可执行函数的输入文件读取,如下所示。
system("executable.exe [anotherexternalfile] [tmp.txt]");
Run Code Online (Sandbox Code Playgroud) 我有一个 maven 项目,如果我尝试进行 mvn 测试,它会在每 12 小时后下载依赖项。如果文件已经存在,我是否可以跳过下载依赖项。我的目的是减少花费的时间并减少网络带宽的使用。
我有一个单行命令,让我们说
grep needle haystack.file
Run Code Online (Sandbox Code Playgroud)
如果我想使用 pwd 命令用当前工作目录替换“needle”怎么办。现在可能可以使用管道,但我需要针部分来显示工作目录和命令的其余部分是相同的。
所以最好是这样的:
grep (pwd) haystack.file
Run Code Online (Sandbox Code Playgroud)
执行时实际上会运行以下命令:
grep /var/www/html/ haystack.file
Run Code Online (Sandbox Code Playgroud)
我做了一些搜索,发现了很多带有管道的例子,但它不能应用于我的场景,因为第一部分 (grep) 和第二部分 (haystack.file) 在应用程序中是固定的。
我在第14行和第16行遇到问题,其中有嵌套的if语句.它返回命令未找到错误,但我测试了那部分代码,它可以在其他地方使用.
#passing the argument page page.html
cat $1 | grep -o "wp-cli.org/commands/cache/\w*/\"" > temp.txt
#creating all pdf files
for i in $(cat temp.txt)
do
source=$(echo $i | grep -o -P "wp-cli.org/commands/cache/\w+")
dest=$(echo $i | grep -o -P "\w+/\"" | grep -o -P "\w+")
#echo $source $dest
wkhtmltopdf $source $dest".pdf"
pdfCount=$(ls *pdf | wc -l)
echo $pdfCount
if [ ! -f sample.pdf ]
then
if [$pdfCount -eq 1]
then
firstPdf=$dest".pdf"
fi
if [$pdfCount -eq 2]
then
pdfunite $firstPdf $dest".pdf" sample.pdf
fi …Run Code Online (Sandbox Code Playgroud) 在NUnit控制台运行程序中,有一个控制台命令用于列出Visual Studio项目中的所有测试。有人知道吗?
我使用版本3.6.1。
基本代码:
my $ContentDate = `date -d '1 hour ago' '+%Y-%m-%e %H:'`;
my $Fail2banNo = `grep Ban /var/log/fail2ban.log | grep $ContentDate | wc -l`;
if (($Fail2banNo > $fail2ban)) {
} else {
}
Run Code Online (Sandbox Code Playgroud)
为什么Perl不会正确完成这些命令?$ fail2ban已经定义为0,所以这不是问题.
fail2ban.log确实包含一个应匹配的行(当从shell运行命令时它匹配):
2018-07-19 xx:11:50,200 fail2ban.actions[3725]: WARNING [iptables] Ban x.x.x.x
Run Code Online (Sandbox Code Playgroud)
我一直得到的错误是:
grep: 10:: No such file or directory
sh: -c: line 1: syntax error near unexpected token `|'
sh: -c: line 1: ` | wc -l'
Argument "" isn't numeric in numeric gt (>) at /usr/local/bin/tmgSupervision.pl line 3431. …Run Code Online (Sandbox Code Playgroud) 我想输出以下内容:
命令:
日期+%T *
01:49:14
Run Code Online (Sandbox Code Playgroud)
但是如何在没有冒号的情况下显示它呢?我正在使用bash命令。
Is there a way to use the word under the cursor in a cscope search in Vim?
If the cursor is over a variable Foo and I want to avoid needing to type Foo again in the command line but would like to assemble :cs f s Foo.
Is there any way I can automate it?
我想知道Linux如何cat解码文件。假设它是一个英文文本文件,该命令似乎使用ASCII解码,但是如何cat解码随机文件呢?