-1

I'm running some code whereby I attempt to subtract a prefix from a string.

When I run the following script, $prefix and $whole appear as desired.

prefix=${dir/*\/};
whole=${f2%.mp3};
echo "$prefix";
echo "$whole";

However, when I run the following I get a "bad substitution" error on the line where I define $final.

prefix=${dir/*\/};
whole=${f2%.mp3};
final=${$whole#$prefix};
echo "$final";

Something must be wrong with my syntax. I've fiddled with it a bit with no luck. Any ideas?

  • syntax...I meant – Yu Buntu Sep 1 '18 at 0:16
  • 1
    Luckily, this problem was not hard to solve.   But you should try to make your question(s) easier to solve by making them easier to understand.   As one of the answers said, you should show sample input and expected output, and maybe explain the steps you are doing in a little bit more detail. – Scott Sep 1 '18 at 6:40
3

It seems that you left one $ too much. Replace $whole to:

final=${whole#$prefix};
  • Woohoo! Thank you, thank you, thank you! :D – Yu Buntu Sep 1 '18 at 1:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.