Perl's variable expansion is the same as shell script's variable expansion

Perl has a feature called variable expansion, which is the same as variable expansion in shell scripts. A shell script is a language for writing commands in the Unix / Linux CUI environment, including sh, bash, csh, ksh, zsh, and other advanced versions of sh.

Perl variable expansion

Perl variable expansion.

my $food = "apple";
my $message = "I like $foo";

Shell script variable expansion

Variable expansion of shell script. Variable names are capitalized according to shell convention.

FOOD = apple
MESSAGE = "I like $FOOD"

Comparison of Perl variable expansion and shell script variable expansion

The part that expands variables using "$" is the same as the shell script. Also, the variable expansion is the same by enclosing it in double quotes.

Perl provides the syntax for variable expansion of shell scripts in the Unix / Linux environment.

In Perl, the variable itself has a "$", which is a bit different from a shell script.

Perl refers to the functionality of the shell

Perl was originally a language that was born in the Unix environment to make it easy to write text processing. Perl is designed to be easy to use for users who wrote shells in the Unix environment.

That's why the variable expansion function used in the shell environment is Perl, and it can be used with the same syntax. You can use the knowledge of variable expansion learned in shell scripts as it is in Perl.

If you're a student, you'll probably learn about the shell in a freshman Unix / Linux server class. The cost of learning Perl is low because you can easily learn Perl's grammar by adding a little to the knowledge you learned there.

While some people over-criticize the grammar of shell scripts, Perl focuses on compatibility and coordination with shell scripts.

If you simply want to execute a few commands, a shell script is simple. If you want to do multi-line text processing, Perl is easy.

Associated Information