0

I have this remote Bash script In GitHub that I already executed successfully line by line, several times (in different versions).

As it is quite frustrating to copy paste all lines each test, I tried to execute the remote Bash script by its raw form with curl, but it fails in various tries:

bash <(curl -s https://raw.githubusercontent.com/benqzq/uncwe/master/install.sh)

or

curl -s https://raw.githubusercontent.com/benqzq/uncwe/master/install.sh | bash

Both failed totally after about 3 seconds with the error:

/dev/fd/63: line 7: $'\r': command not found

I theorized I might need to translate out all carriage returns, hence tried:

curl -s https://raw.githubusercontent.com/benqzq/uncwe/master/install.sh | tr -d '\r' | bash

This brought partial execution of the script. For example, while apt-get install, export,git clone, rm -rf ${repo}/.git/, and a few other operations went fine, the wget/unzip and processing of a few files with leading tabs failed to be processed correctly.

I thought it might be that GitHub GUI changes leading whitespaces from tab to space and vice versa, in some sections in the code, so I tried to change all leading whitespaces into tabulations:

curl -s https://raw.githubusercontent.com/benqzq/uncwe/master/install.sh | sed "s/^ */\t/" | tr -d '\r' | bash

The result was seemingly identical to the previous one.

Due these 4 ways fail, I wonder what else is available. Sadly I've yet to find other examples in Google.

Maybe I'm having these problems because I usually work from Windows 10 and carriage returns are added to each file, but than one could ask why did "translating them out" as in of the code examples resulted in bad execution.

  • Unless there are reasons for doing so, I would suggest sticking with curl -s -L https://.... | tr -d '\r' | bash -x, which show the commands being executed, follows redirections and removes carridge returns. The raw content does seem to have lines ending \r\n, so you will need to remove the \r. Bash is not python, you don't need to worry about indentation. Can you edit your question to explain what is failing once you have removed the \r, or clarify that you want to know why things fail if you don't remove the \r. – icarus Feb 12 '18 at 0:42
  • 1
    You might find this article helpful to configure github to not store the \r characters. help.github.com/articles/dealing-with-line-endings – icarus Feb 12 '18 at 0:52
0

I was able to solve it using dos2unix.

I installed it:

sudo apt-get update
sudo apt-get install dos2unix

I then ran the curl, to download the content to stdout. I piped the content in stdout through dos2unix to change it, then through bash to execute it.

sudo curl -s https://raw.githubusercontent.com/benqzq/ulcwe/master/install.sh | dos2unix | bash

Your Answer

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.