Home > Software design >  Issue when running external command
Issue when running external command

Time:11-15

I'm using backticks to run an external command in perl, but I've got a problem.

What I want to do is to run

`mount /dev/sdb2 /mnt`

But the sdb2 is only the right parameter when I'm running it with this disk, I want to be able to run the script with any disk.

The script gets information about the source disk that I'm using (in this case the sdb), and puts it as "$source". But when I try the:

`mount $source /mnt`

It says "mount: you must specify the filesystem type"

In this case the program asks for the "2"

Any idea on how to make the script find the number that is requried, or at least how to add a "2" after the "$source" so that

$source = /dev/sdb2 and not /dev/sdb

CodePudding user response:

Use curly braces when expanding the variable:

`mount ${source}2 /mnt`

NB. make sure you validate $sources value, as to not introduce code injection vulnerabilities.

  •  Tags:  
  • perl
  • Related