0

In pythonanywhere’s bash I am trying to remove the file:

rm /home/olb/Email Thu, 19 Mar 2020 18:49:16 +0000 =?UTF-8?Q?Update_from_GOV.UK_=E2=80=93_Coronavirus_(COV?= =?UTF-8?Q?ID-19)_guidance_for_the_charity_sector?=

The error I get is:

bash: syntax error near unexpected token `(‘

I have tried to escape the ( via:

rm /home/olb/Email Thu, 19 Mar 2020 18:49:16 +0000 =?UTF-8?Q?Update_from_GOV.UK_=E2=80=93_Coronavirus_\(COV?= =?UTF-8?Q?ID-19\)_guidance_for_the_charity_sector?=

But seems to split the file into: enter image description here I have also tried:

rm /home/olb/ \Email Thu, 19 Mar 2020 18:49:16 +0000 =?UTF-8?Q?Update_from_GOV.UK_=E2=80=93_Coronavirus_\(COV?= =?UTF-8?Q?ID-19\)_guidance_for_the_charity_sector?=

Thanks for any help

New contributor
Ollie is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
13

Single quote the name. This is needed as the name contains not only ( but spaces and other characters that would be interpreted by the shell if left unquoted. The shell would split the name on the unquoted spaces and treat each generated word as a separate filename pattern to remove (you see this in the error message that you got), and the ? characters are globbing characters that would potentially match a single character in existing filenames (unlikely, but still).

rm -i ~olb/'Email Thu, 19 Mar 2020 18:49:16 +0000 =?UTF-8?Q?Update_from_GOV.UK_=E2=80=93_Coronavirus_(COV?= =?UTF-8?Q?ID-19)_guidance_for_the_charity_sector?='

Alternatively, use a filename globbing pattern that matches the filename uniquely,

rm -i ~olb/Email*COV*guidance_for_the_charity_sector*

Note that you need to be sure that this only matches the one file that you're interested in removing. You can check this by replacing rm in the command above with printf '%s\n' or echo and inspect the result of that modified command.

I'm also using rm -i here to give you an interactive prompt for each deletion.

You could use the same approach to rename the file to a saner name:

mv -i ~olb/Email*COV*guidance_for_the_charity_sector* /home/olb/COV_guidance_for_the_charity_sector.txt
  • 18
    tab completion should also quote the filename properly in Bash. it can be used to check that the glob pattern only matches the one file – ilkkachu Mar 26 at 10:14

Your Answer

Ollie is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.