0

I am writing a shell script to download and install my company's MSP agent on new Mac computers that a client of ours is going to purchase. When I run the following command in the terminal it works perfectly:

curl --output AgentInstall.zip <url>

however when I put the same exact line in my script it returns the following error on running:

curl: (3) URL using bad/illegal format or missing URL

I'm not doing anything fancy like embedding the command in a variable. I've tried more variations on this then I can count, different options such as -o, -O, -oO, and others, I've tried using

$https://<url>

I've tried wrapping the URL in "", but nothing I have tried has given any sort of success. The thing that baffles me the most is that the command I posted above works when pasted directly into the terminal, but not the script. I am brand new to Shell/Bash scripting, so I'm sure it's some newbie thing that I'm missing, but if someone could point out what that is I would greatly appreciate it. Thanks!

EDIT To include Minimal Reproducible Example:

I have included my script with the URL changed to the Firefox download link. I have confirmed that once again, the command pasted into the terminal works perfectly but when run in the script it returns the above error.

#!/bin/sh
#
#download and extract agent
#
mkdir /tmp/AgentInstall
cd /tmp/AgentInstall
curl --output AgentInstall.zip https://www.mozilla.org/en-US/firefox/download/thanks/
unzip AgentInstall.zip
#
Toto
  • 89,455
  • 62
  • 89
  • 125
jt1990
  • 3
  • 2
  • `` isn't in your line, so it can't be the "exact same" line. – Charles Duffy Jul 16 '21 at 15:14
  • That said, one possibility is that your script has hidden characters, like DOS line endings. – Charles Duffy Jul 16 '21 at 15:14
  • 2
    Try running `bash -x yourscript`; it if prints the URL like `$'http://example.com/whatever\r'`, with `$'` and `\r'`, you know your file has CRLF newlines instead of valid UNIX LF-only newlines. – Charles Duffy Jul 16 '21 at 15:15
  • 2
    Beyond that, though -- we _really_ need a [mre] to solve this kind of thing. – Charles Duffy Jul 16 '21 at 15:15
  • Do you have a reason for thinking `$https://` would work, or are you just throwing random shell-like constructs into your script in hopes that something will magically work? – chepner Jul 16 '21 at 15:20
  • I didn't want to post the exact URL because it's a direct link to the agent installer, something I didn't want public, however I have copied the line out of my script and pasted it into the terminal and it worked perfectly. I will look into the newlines thing. And I was looking at this: https://linuxhint.com/curl_bash_examples/ Which gave the example of `${url}` – jt1990 Jul 16 '21 at 15:25
  • @CharlesDuffy, yes it does return the \r when I run the command. How do I fix that? I'm using Notepad++ to write the script. – jt1990 Jul 16 '21 at 16:01
  • @CharlesDuffy - Figured out how to switch from CRLF to LF and it worked perfectly. Thank you for your help!! – jt1990 Jul 16 '21 at 16:10

1 Answers1

0

Error was caused by CRLF newlines instead of LF newlines. Thank you @Charles Duffy for your help!

jt1990
  • 3
  • 2