小编Faz*_*lin的帖子

使用Getopt :: Long将值分配给同一个变量

我试着写一个小的perl脚本来理解Getopt::Long.

以下是脚本:

#!/usr/bin/perl

use strict;
use Getopt::Long;

my $op_type = "";
my @q_users;

GetOptions (
  'query' => $op_type = "query",
  'create' => $op_type = "create",
  'modify' => $op_type = "modify",
  'delete' => $op_type = "delete",
  'user=s' => \@q_users
) or usage ("Invalid options.");

print "operation : $op_type\n";
Run Code Online (Sandbox Code Playgroud)

当我运行此脚本时,如下所示:

$ ./all_opt.pl --query
operation : delete
Run Code Online (Sandbox Code Playgroud)

我假设在我的程序中缺少某种破坏声明.我期待operation : query结果.

请让我知道我在这里缺少什么.

perl getopt-long

3
推荐指数
1
解决办法
142
查看次数

如果字符串有连字符,记录器将失败

我试图用来logger记录我的脚本中的消息.我使用logger如下所示:

logger -p auth.notice -t "TEST" "$line"
Run Code Online (Sandbox Code Playgroud)

如果$line有一些带连字符的字符串,例如:

line="-retries"
Run Code Online (Sandbox Code Playgroud)

然后logger失败并出现错误:

logger: invalid option -- r
usage: logger [-is] [-f file] [-p pri] [-t tag] [-u socket] [ message ... ]
Run Code Online (Sandbox Code Playgroud)

请帮我摆脱这个错误.我也尝试过:

logger -p auth.notice -t "TEST" "$(echo $line)"
Run Code Online (Sandbox Code Playgroud)

linux string bash logging

1
推荐指数
1
解决办法
210
查看次数

标签 统计

bash ×1

getopt-long ×1

linux ×1

logging ×1

perl ×1

string ×1