Simple string manipulation

Hello,

I would like to make simple string manipulation but since i am new in shell scripting some strange stuff are uncomprehensible to me:

I would like to pick up the name of a file and put it in a variable:

shadok@computer:~$a= folder/fil*.dat
shadok@computer:~$echo $a
folder/filename.dat
shadok@computer:~$echo ${a:7}
fil*.dat

Why when i want to remove the folder name, the expression change ? How can i keep the ENTIRE name "filename.dat" ?

thanks very much ! :slight_smile:

file_name=$(ls /tmp/test)
echo $file_name

--ahamed

ahamed,

ok, thanks it works :slight_smile:

the answer is confused me. Then confirm it works makes me more confused.

for a in folder/file*.dat
do
  echo ${a#*/}
done

or by basename command

basename $a