How do I execute a remote script as a build phase in xcode? - xcode

I have a remote script which I can execute from command line without an issue:
bash <(curl -sSL 'goo.gl/p1GPQw') 29165BE4-EA61-8228-9F33-A9B9DAD481A0 ./Info.plist
Problem comes when I try to use it in as a build phase of my iOS app (to update a build number).
The error log:
/Users/pr.......: line 2: syntax error near unexpected token `('
/Users/pr.......: line 2: `bash <(curl -sSL 'goo.gl/p1GPQw') 7CD17FC7-E724-7240-34ED-927122733119 ./Info.plist'
So the question is, are there any limitations in what you can through xcode execute or is it some error in syntax?
Update:
If I change the /bin/sh to /bin/bash, it works ... so the updated question is, what is the /bin/sh equivalent of bash <(curl -sSL 'goo.gl/p1GPQw') 29165BE4-EA61-8228-9F33-A9B9DAD481A0 ./Info.plist as making users change this is another complication that can make the entire thing go sideways.

I tried to simplify the problem, for purpose of reproducibility:
This is 1.sh script:
#!/usr/bin/bash
echo echo Hello World
echo echo Today : $(date)
When run in /bin/bash, it works fine:
bash $ bash <(./1.sh)
Hello World
Today : Thu, Sep 22, 2016 2:32:19 AM
$
When run in /bin/sh it gives an error:
sh $ bash <(./1.sh)
sh: syntax error near unexpected token `('
sh $
But, the following should work fine even in /bin/sh:
sh $ bash -c "bash <(./1.sh)"
Hello World
Today : Thu, Sep 22, 2016 2:35:35 AM
sh $

Related

bash: syntax error near unexpected token `newline' for "&! "

I have the following script.sh running in zsh. But since I am running the script as sudo user used shell differs between each other.
#!/bin/bash
echo $SHELL
nohup geth --syncmode fast --cache=1024 > geth_server.out 2>&1 &!
Output in macOS:
$ chmod +x script.sh
$ sudo ./script.sh
/bin/sh
syntax error near unexpected token `newline'
which generated following error on macOS but works fine in linux: syntax error near unexpected token newline'`
Output in linux:
$ chmod +x script.sh
$ sudo ./script.sh
/bin/bash
# works fine
The error seems like generated due to ! at the end of the line. Is there anyway to fix this, what may be the reason for this? Exact same script works fine in linux environment

New to MINGW64 - command not found?

I've been using MINGW64 for about 4 hours. So go easy on me. I'm having a problem where commands work when typed directly into the MINGW64 console, but fail when run from a simple .sh script.
Administrator#EC2AMAZ-I2CVOT2 MINGW64 /c/BuildAgent
$ drewtemp="hihi"
Administrator#EC2AMAZ-I2CVOT2 MINGW64 /c/BuildAgent
$ echo "${drewtemp}"
hihi
Administrator#EC2AMAZ-I2CVOT2 MINGW64 /c/BuildAgent
$ cat test.sh
#!/usr/bin/sh
unity="hi"
echo "${unity}"
Administrator#EC2AMAZ-I2CVOT2 MINGW64 /c/BuildAgent
$ ./test.sh
./test.sh: line 2: unity=hi: command not found
Can anyone tell me why this simple sh script results in "command not found"?
Thanks!

Cannot use process substitution during docker build because bash goes into posix mode

In a Dockerfile, I want to use process substitution:
RUN echo <(echo '$DATA:'"$DATA")
But docker build runs every RUN command with /bin/sh. Apparently being run as sh causes bash to switch to POSIX mode, which does not allow process substitution:
/bin/sh: -c: line 0: syntax error near unexpected token `('
I tried switching off POSIX mode:
RUN set +o posix && echo <(echo '$DATA:'"$DATA")
But it seems the syntax error happens even before the first command is run. Same if I replace && with ;.
Note that the command (even the one that I used as a simplified example here) contains both single and double quotes, so I can't simply prepend bash -c.
The used shell is actually a bash, but it is invoked as /bin/sh by docker:
Step 7 : RUN ls -l /bin/sh
---> Running in 93a9809e12a7
lrwxrwxrwx 1 root root 9 Dec 28 03:38 /bin/sh -> /bin/bash
If you are sure you have bash in your image being built, then you can change the shell invokation by using the SHELL command, which I described in another question.
You can use SHELL [ "/bin/bash", "-c" ]. Consider:
$ docker build --no-cache - < <(echo '
> FROM fedora
> RUN cat <(echo hello world)
> ')
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM fedora
---> ef49352c9c21
Step 2/2 : RUN cat <(echo hello world)
---> Running in 573730ced3a3
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `cat <(echo hello world)'
The command '/bin/sh -c cat <(echo hello world)' returned a non-zero code: 1
$ docker build --no-cache - < <(echo '
> FROM fedora
> SHELL ["/bin/bash", "-c"]
> RUN cat <(echo hello world)
> ')
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM fedora
---> ef49352c9c21
Step 2/3 : SHELL ["/bin/bash", "-c"]
---> Running in e78260e6de42
Removing intermediate container e78260e6de42
---> ff6ec782a9f6
Step 3/3 : RUN cat <(echo hello world)
---> Running in afbb42bba5b4
hello world
Removing intermediate container afbb42bba5b4
---> 25f756dcff9b
Successfully built 25f756dcff9b
Assuming your sh is not bash, you can't use process substitution in shell mode directly; you need to spawn a bash session (non-login, non-interactive here):
RUN [ "/bin/bash", "-c", "echo <(echo '$DATA:'\"$DATA\")" ]
Here i have used the json (aka exec) form to make sure the quotes are easily managed, here you just need to escape quotes around $DATA: \"$DATA\" -- to prevent json interpretation beforehand.
If your sh is in fact bash, this should do:
RUN "echo <(echo '$DATA:'"$DATA")"
Also this just outputs the file descriptor, i am not rally sure about your plan.

Bash functions inside process substitution

Getting an error trying to call a function inside a process substitution.
Is there any way to do this?
#!/bin/bash
function testfunc
{
echo "bork"
}
diff <(testfunc) <(echo "bork")
The error is:
bork.sh: line 7: syntax error near unexpected token `('
bork.sh: line 7: `diff <(testfunc) <(echo "bork")'
--Update--
Problem was calling sh bork.sh, instead of bash ./bork.sh . Moral of the story make sure which shell you are executing with.
There's no problem here:
$ chmod +x test.sh
$ ./test.sh
Clear diff. No problem!
$ bash -x ./test.sh
+ diff /dev/fd/63 /dev/fd/62
++ testfunc
++ echo bork
++ echo bork
Proof that it worked
Troubleshooting:
Maybe you
run in a restricted shell
you don't have /dev/fd available/mounted correctly (due to somekind of secure chroot jail?)
The problem is probably that you're running the command with sh instead of bash.
$ cat > xx.sh
#!/bin/bash
function testfunc
{
echo "bork"
}
diff <(testfunc) <(echo "bork")
$ sh xx.sh
xx.sh: line 7: syntax error near unexpected token `('
xx.sh: line 7: `diff <(testfunc) <(echo "bork")'
$ bash xx.sh
$
The process substitution is not portable to the shell in /bin/sh. See the Bash manual on POSIX mode and bullet 28:
Process substitution is not available.
Tested on Mac OS X 10.10.5 (Yosemite).

Bash unexpected token when using "&;"

I'm launching a script via SSH with this command:
ssh myuser#myhost "bash -x -c 'source config.sh; nohup Start_JBoss.sh > /dev/null &; sleep 5'"
however I'm hitting an error:
Connecting to: myhost with myuser
Password:
bash: -c: line 0: syntax error near unexpected token `;'
bash: -c: line 0: `source config.sh; nohup Start_JBoss.sh > /dev/null &; sleep 5'
What's I'm doing wrong here? I know that SSH is not the cause as the same command fails into a local shell.
I've read some similar thread where there's some mention on Bash version as culprit for some other kind of unexpected token issue so adding here just for reference in case is needed:
bash -version
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Guess I did not searched hard enough as I found out solution here https://superuser.com/questions/269429/why-did-after-return-an-unexpected-token-error-in-bash
but leaving here as reference.
Basically if you send to background a process you do not need to use ; as the shell is already ready to accept new command.

Resources