Skip to main content

I am trying to remove all ".s" files in a folder that can be derived by ".c" source files. This is my code

for cfile in *.c; do

for cfile in *.c; do 
    #replace the last letter with s
    cfile=${cfile/%c/s}
    for sfile in *.s; do
        #compare cfile with sfile; if exists delete sfile
        if [ $chile==$sfile$cfile==$sfile ]; then
            rm $sfile;
        fi
    done
done

But this code deletes all the ".s" files. I think it's not comparing the filenames properly. Can someone please help.

I am trying to remove all ".s" files in a folder that can be derived by ".c" source files. This is my code

for cfile in *.c; do

    #replace the last letter with s
    cfile=${cfile/%c/s}
    for sfile in *.s; do
        #compare cfile with sfile; if exists delete sfile
        if [ $chile==$sfile ]; then
            rm $sfile;
        fi
    done

But this code deletes all the ".s" files. I think it's not comparing the filenames properly. Can someone please help.

I am trying to remove all ".s" files in a folder that can be derived by ".c" source files. This is my code

for cfile in *.c; do 
    #replace the last letter with s
    cfile=${cfile/%c/s}
    for sfile in *.s; do
        #compare cfile with sfile; if exists delete sfile
        if [ $cfile==$sfile ]; then
            rm $sfile;
        fi
    done
done

But this code deletes all the ".s" files. I think it's not comparing the filenames properly. Can someone please help.

Source Link
user2709885
  • 423
  • 2
  • 8
  • 17

How can I compare two strings in bash?

I am trying to remove all ".s" files in a folder that can be derived by ".c" source files. This is my code

for cfile in *.c; do

    #replace the last letter with s
    cfile=${cfile/%c/s}
    for sfile in *.s; do
        #compare cfile with sfile; if exists delete sfile
        if [ $chile==$sfile ]; then
            rm $sfile;
        fi
    done

But this code deletes all the ".s" files. I think it's not comparing the filenames properly. Can someone please help.