-2

i' m trying to extract the file extension in bash without using regex. i' ve tried the following

extension = $(echo $1 | cut -f 2 -d '.')

extension is the variable $1 contains something like: file.txt or file.pdf etc. this code is outputting:

./prova.sh: 3: ./prova.sh: extension: not found

1 Answers1

0
extension=$(echo sample.txt | cut -f 2 -d '.')
echo $extension 

Above command will give you the output as expected txt