0

The following commands and question is merely aim to figure out proper syntax, so please don't seek for any deep purpose behind it, but rather if you know the proper syntax this would be of a huge help to me.

I have the following: *using here perl -e in order to mimic a perl file that calls to system() command in order to execute unix commands.

perl -e '$i="file.bed"; system("j=$i; echo ${i} ;echo \${j}; echo \${j%.*};")';

this command nicely outputs:

file.bed
file.bed
file

I'd like to add another echo that replaces the suffix ".bed" to the suffix ".bam" I tried:

perl -e '$i="file.bed"; system("j=$i; echo ${i} ;echo \${j}; echo \${j%.*}; echo \${j/.bed/.bam}")';

but i get:

file.bed
file.bed
file
sh: 1: Bad substitution

same goes for:

perl -e '$i="file.bed"; system("j=$i; echo ${i} ;echo \${j}; echo \${j%.*}; echo \${j\/.bed\/.bam}")';

So for some reason the suffix removal [%.*] works just fine within system(), but {//} substitution fails.

Any ideas?

1
  • 1
    @toolic, system doesn't use tcsh, so that's a rather useless statement. Commented Mar 7, 2016 at 16:34

1 Answer 1

5
perl -e '$i="file.bed"; system("...")'

is short for

perl -e '$i="file.bed"; system("/bin/sh", "-c", "...")'

but ${j/.bed/.bam} isn't supported by sh. Use

perl -e '$i="file.bed"; system("bash", "-c", "...")'
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.