Skip to content
Advertisement

Executing an if else shell command from perl

I have never run into this scenario before so I could use a little help. I am trying to issue an if/else statement from a shell command but within perl. I’ve tried system and exec with no success. Here’s a sample of the code

JavaScript

If I run the command if ! dpkg -l curl &> /dev/null; then apt-get install curl -y; fi in shell it works fine but executing it from perl is skips the if part and goes right on to installing it.

Advertisement

Answer

The if works perfectly fine.

JavaScript

There is a problem, though. What you posted is a bash command, but system(EXPR) is short for system('/bin/sh', '-c', EXPR). Simply replacing

JavaScript

with

JavaScript

should do the trick.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement