我有这个配置文件
dbUser=customer
dbPass=passwrd
dbSid=customer.shadow
passwdFile=/production/etc-user
tmpUsers=tmpuser
htpasswd=/usr/local/apache2/bin/htpasswd
Run Code Online (Sandbox Code Playgroud)
然后是一个读取配置文件的脚本:
#!/usr/local/bin/perl
use warnings;
use strict;
readConfig();
# reads in a config file
sub readConfig {
my $configFile = $ARGV[0];
my %prefs ="" ;
open (CONFIG, "< $configFile") or die "Cannot open $configFile for reading: $!\n";
while (<CONFIG>) {
chomp; # kill newlines
s/#.*//; # ignore comments
s/^\s+//; # ignore leading whitespace
s/\s+$//; # ignore trailing whitespace
next unless length;
my($var,$value) = split(/\s*=\s*/, $_, 2);
$prefs{$var} = $value;
print "$var : $prefs{$var}\n";
} …Run Code Online (Sandbox Code Playgroud) 我建立了一个简单的子例程,并且对调用它是否需要括号有疑问。
#!/usr/bin/perl
sub echo {
print "@_ \n" ;
}
echo(@ARGV);
Run Code Online (Sandbox Code Playgroud)
当我使用
echo @ARGV
Run Code Online (Sandbox Code Playgroud)
要么
echo (@ARGV)
Run Code Online (Sandbox Code Playgroud)
或(无空格)
echo(@ARGV)
Run Code Online (Sandbox Code Playgroud)
他们都工作。哪一个是正确的?
使用冒号有什么区别,这意味着"什么都不做"和继续,这意味着跳过.
if [[ -s $file ]] ; then
:
fi
if [[ -s $file ]] ; then
continue
fi
Run Code Online (Sandbox Code Playgroud) 我将一些日期参数放入脚本中
#!/bin/bash
set -x
today=$(date +%Y%m%d)
while [ ! $# -eq 0 ] #while number of arguments is NOT zero, do this
do
if [[ "$1" = "--test" ]] || [[ "$1" = "-t" ]] ; then
today=$(date +%Y%m%d).test
elif [[ "$1" = "--yesterday" ]] || [[ "$1" = "-y" ]] ; then
DOW=$(date +%u)
if [[ "$DOW" = "1" ]] ; then
today=$(date --date="3 days ago" +%Y%m%d)
else
today=$(date -d "yesterday 13:00" +%Y%m%d)
fi
fi
done
echo "$today"
exit …Run Code Online (Sandbox Code Playgroud) 这是来自其他成功脚本的切片.我需要做的是打印一个<tr>然后打印<td>$stat_array</td>四次,退出,打印</tr>再打印一份<tr>,打印在未来四年$stat_arrays中@stat_array,等等,然后一个</table>.
它的作用是打印所有八个$start_arrays然后a </tr>.
my @table_header = ("Process", "Region_Permission","Region Violation","Message Type");
my @stat_array =("ibfarm102 - localtick" ," Greenwich" ," hibmis100 - procHKHD2 - Hongkong" , "PidMonRsp" ," ibfarm102 - localtick", "Greenwich" ,"hibmis100 - procHKHD2 - Hongkong", "PidMonReq");
print MAIL "<tr>\n";
for ($i = 0 ; $i <$#table_header ; $i = $i + $#table_header) {
foreach my $stat_array(@stat_array) {
print MAIL "<td>$stat_array</td>\n";
}
print MAIL …Run Code Online (Sandbox Code Playgroud) 当我捕获这个文件时,我得到6行(这是一个差异文件)
bash-3.00$ cat /tmp/voo
18633a18634
> sashabSTP
18634a18636
> sashatSTP
21545a21548
> yheebash-3.00$
Run Code Online (Sandbox Code Playgroud)
然而,当我逐行阅读时,我只得到5行.
bash-3.00$ while read line ; do echo $line ; done < /tmp/voo
18633a18634
> sashaSTP
18634a18636
> sashatSTP
21545a21548
Run Code Online (Sandbox Code Playgroud)
或这个
bash-3.00$ cat /tmp/voo | while read line ; do echo $line ; done
18633a18634
> sashabSTP
18634a18636
> sashatSTP
21545a21548
bash-3.00$
Run Code Online (Sandbox Code Playgroud)
我错过了while循环中的最后一行'yhee'.
我开始使用printf而不是echo.我的第一个问题printf %s是:
#!/bin/bash
danny=$(tail -1 /come/and/play/with/US.log| ~/walt/convert_gm_est)
printf "%s" $danny
Run Code Online (Sandbox Code Playgroud)
08:02.020ZINFO<-casper/casperbox001wowSYSSTATS[sz=21,tag=0,aux=0]process_log2221397800
Run Code Online (Sandbox Code Playgroud)
它消除了字符串中的所有空格.所以我在格式说明符后添加了一个空格.字符串看起来更好用空格加上我可以很容易地用awk消除时间.我没有在互联网上看到这个.我尝试过"%s\s",但没有用.这是使用格式说明符的标准程序 - 之后使用空格%s?这是做到这一点的方式还是我错过了什么?
#!/bin/bash
danny=$(tail -1 /come/and/play/with/US.log| ~/walt/convert_gm_est)
printf "%s " $danny
Run Code Online (Sandbox Code Playgroud)
08:02.020Z INFO <- casper/casperbox001wow SYSSTATS[sz=21, tag=0, aux=0] process_log 2221397 80 0 casper@casperbox001wow:~$
Run Code Online (Sandbox Code Playgroud) 我试图打印出单引号包围的文本.
/bin/bash -lc '/home/CASPER_REPORTS/scripts/CASPER_gen_report.sh CASPER_1'
/bin/bash -lc '/home/CASPER_REPORTS/scripts/CASPER_gen_report.sh CASPER_1A'
/bin/bash -lc '/home/CASPER_REPORTS/scripts/CASPER_gen_report.sh CASPER_2'
/bin/bash -lc '/home/CASPER_REPORTS/scripts/CASPER_gen_report.sh CASPER_3'
/bin/bash -lc '/home/CASPER_REPORTS/scripts/CASPER_gen_report.sh CASPER_3A'
Run Code Online (Sandbox Code Playgroud)
布尔值我猜这意味着perl会看到字符串.
$ cat /tmp/casper_reports | perl -nle 'print /'.*'/'
1
1
1
1
1
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试用括号捕获它时,它会抛出一个错误
$ cat /tmp/boobomb | perl -nle 'print /'(.*)'/'
-bash: syntax error near unexpected token `('
Run Code Online (Sandbox Code Playgroud) 当我将 Perl@ARGV数组分配给一个变量时,如果我不使用引号,它会给出数组中的字符串数,而不是数组中的字符串数。
这叫什么 - 我以为这是取消引用,但事实并非如此。现在我称它为我需要在 Perl 中记住的另一件事。
#!/usr/bin/perl
use strict ;
use warnings;
my $str = "@ARGV" ;
#my $str = @ARGV ;
#my $str = 'geeks, for, geeks';
my @spl = split(', ' , $str);
foreach my $i (@spl) {
print "$i\n" ;
}
Run Code Online (Sandbox Code Playgroud) We changed over from MindAlign to Symphony Chat at work. Symphony seems akin to ZenDesk chat software. We use the Symphony Chat to assign tickets to people.
When I cut and paste from the Symphony terminal it comes out like this (it has no newlines - it is just one big contiguous line of text):
16th Jun 2020 7:57:18 am Tom Lewin: WJ: RE: BART failed STP - JIMBCI - INC101981467816th Jun 2020 8:20:38 am Nathan Winslow: II : RE: …Run Code Online (Sandbox Code Playgroud)