0

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
5
  • 4
    I don't see anything to fix. Are you asking how to make your program ask for the partition number? If so, please edit your question to clarify, and post the code you have tried so far. Commented Jan 27, 2012 at 8:41
  • Is this clear enough or should I clarify more? Thanks for the pointer btw, I'm new to this and I need all the help I can get! =) Commented Jan 27, 2012 at 9:13
  • Not really. Nothing can "guess" the right partition number (the "2" you talk about). Either your program needs to list all the partitions on that drive (can do that with a glob) and try them all (not a good idea), or you need to get the right input from the user. The last two lines you added have me completely puzzled as to what they are supposed to mean/show. Commented Jan 27, 2012 at 9:16
  • There, now I'm practially only asking how to implant a 2 after $source, is this possible? Commented Jan 27, 2012 at 9:20
  • Are you really asking how to concatenate strings in Perl? Commented Jan 27, 2012 at 9:21

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.