Need some help with this one. So this command works and displays the info I desire which is the Last-Modified response header:

ubuntu:~$ curl -s -I "https://someurl/?someparam" | grep -Fi Last-Modified

which returns:

**last-modified: Tue, 22 Mar 2022 17:33:35 GMT**

What I want to do is store this into a variable - say "Last-Mod" and then compare that with the current date to see if the content has been refreshed (it is a file) within the last 1-2 days. If it has been refreshed, then I want to go ahead and download it. I have tried various syntax like:

Last-Mod="$(curl -s -I https://someurl/?parama=a&paramb=b | grep -Fi Last-Modified)"

but I keep getting errors. Any pointers?

Thanks, Jeff

  • 3
    Why did you decide to drop the quotes around the URL in your second command?
    – Kusalananda
    Mar 24, 2022 at 0:18
  • I have tried it both ways and same result. Maybe it is the pipe?
    – Jeff Sani
    Mar 24, 2022 at 3:25

2 Answers 2


As mentioned in the comments your errors are probably due to the unquoted & in your URL. This will try to run everything before it as a background process and then try to run everything after it as a new command.

You need to either quote the URL or escape that ampersand

Last-Mod="$(curl -s -I 'https://someurl/?parama=a&paramb=b' | grep -Fi Last-Modified)"

See 3.2.4 Lists of Commands

If a command is terminated by the control operator ‘&’, the shell executes the command asynchronously in a subshell. This is known as executing the command in the background, and these are referred to as asynchronous commands. The shell does not wait for the command to finish, and the return status is 0 (true).

  • This is what I am trying: admin@ubuntu:~$ Last-Mod="$(curl -s -I 'download.maxmind.com/app/…{LICENSE_KEY}&suffix=zip' | grep -Fi Last-Modified)" Last-Mod=: command not found admin@ubuntu:~$
    – Jeff Sani
    Mar 24, 2022 at 2:41
  • @JeffSani: If LICENSE_KEY is a variable you need to use double quotes instead of single quotes.
    – jesse_b
    Mar 24, 2022 at 12:00

Variable names in bash can not contain a hyphen (-), only:


A word consisting solely of letters, numbers, and underscores, and beginning with a letter or underscore. Names are used as shell variable and function names. Also referred to as an identifier.

(from the documentation of bash). Rename Last-Mod to Last_Mod to make the assignment work.

  • This was the issue. Even removing the hyphen also worked.
    – Jeff Sani
    Mar 24, 2022 at 17:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .