How do I put basename into a variable? How do I put basename into a variable? bash bash

How do I put basename into a variable?


Use the command substitution $(...) mechanism:

test=$(basename "$file" .deb)

You can also use backquotes, but these are not recommended in modern scripts (mainly because they don't nest as well as the $(...) notation).

test=`basename "$file" .deb`

You need to know about backquotes in order to interpret other people's scripts; you shouldn't be using them in your own.

Note the use of quotes around "$file"; this ensures that spaces in filenames are handled correctly.