FreeKB - Perl (Scripting) Native operating system command (`backticks`)
Perl (Scripting) - Native operating system command (`backticks`)

Backticks can be used to run a command in perl that is native to the underlying operating system. For example, let's say a Perl script is running on a Linux server. The following script is an example of how backticks can be used to run native Linux commands in Perl. Running this Perl script will print FooBar to the console.

`echo FooBar`;


The prior example was not very practical, as you could print FooBar to the console in native Perl. However, there are some scenarios where a native operating system command is either just a heck of a lot easier, or there is no Perl command to run the native operating system command. As an example, let's say you want to view a certificate in a Java keystore. This certainly would be best done using a native operating system command.

`keytool -list -v -keystore /path/to/example.jks -storepass secret`;


Sometimes, it makes sense to store the native operating system command you want to run as a Perl variable. 

my $file = "cat /path/to/example.txt";


Then, you can run the command using backticks and pipe native operating system commands.

my $bar = `$foo | grep Hello`;


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter a7d6a in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |