If you want to assign the output of a command to a variable, you must execute it either with backquotes or with a special quote:
file=`basename "$1"` file=$(basename "$1")
To remove the file name extension, you must do
ext=${file#*.}
this will get the value of $file , and then delete everything before the period (for which it is necessary). If your file name contains periods, you should use ext=${file##*.} , Where ## tells bash to delete the longest line that matches instead of the shortest, so it will be deleted until the last period, and not the first.
Your echo $basename $1 is simple. It tells bash to print the value of a variable called $basename and the value of $1 , which is the first argument to the script (or function).
If you want to print the command you are trying to execute, do the following:
echo basename $1
If you are trying to print the output of a command, you can do one of the following:
echo $(basename "$1") echo "$file" basename "$1"
Hope this helps =)
Janito Vaqueiro Ferreira Filho
source share