Help with renaming files in folder

Hello,
I want to rename more than 100 files. These files have "?" in there existing file name but I want to rename files to there first part before "?" token. I have tried using for loop but it isn't working so help following is the sample filename and for loop that am trying to use:
example of file name: abcde?fghijk
Expected file name:abcde
For Loop:

for i in $( ls * ) ; do echo $i;  echo "$( echo $i | sed -e 's/?.*//g' )"; done

am I missing something in above loop or is there a better way to deal with this?
Please help!

for f in *\?*; do
  mv -- "$f" "${f%\?*}"
done  
1 Like

radoulov, thanks so much for your reply and the tip. I discovered another way to rename the files with a token "?" as follows:

for file in ls *
do
    echo "will move files from ${file} ==> ${file%%\?*}"
        mv ${file} ${file%%\?*}
done

In case someone else run into situation like mine, they can use either method and both works....
thanks,
ls_lrta

without for loop

$ ls -1 *\?* | nawk -F\? '{print "mv "$0" "$1}' | sh