gpt4 book ai didi

linux - 如何正确运行 Perl "one liner"命令行脚本?

转载 作者:IT王子 更新时间:2023-10-29 00:21:17 25 4
gpt4 key购买 nike

我已经浏览了很多教程,但我仍然无法弄清楚我做错了什么......我正在尝试下面的代码(在 .pl Perl 文件中,作为可执行文件):

#!/usr/bin/perl

perl -e 'print "Hello";'

我运行这个脚本并得到:

Execution of /home/user1/Desktop/file_backups.pl aborted due to compilation errors.

(我刚开始使用Perl调用Linux命令行。)

最佳答案

尝试:

#!/usr/bin/perl
# This is a comment ~~~
# This script will be run as a Perl script
# since 'perl' isn't a keyword or function in Perl
# something like this must fail:
#
# perl -e 'print "Hello";'
#
# The following should work.

print "Hello"; print " World\n";

或者,如果您希望 shell 脚本执行 Perl 代码:

#!/bin/sh
# That's a Bash script ~~~
# It's just a command line in a file ...

perl -e 'print "Hello World";'

背景:#! 是一个 interpreter directive .

When the command is executed, it is converted to an execution of the interpreter.

关于linux - 如何正确运行 Perl "one liner"命令行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3220215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com