0

I have a script that when I run from a file manager (Filza), it return an error saying

command substitution: syntax error near unexpected token `('.
line 56: `paste -d'\n' <(echo "$var1") <(echo "$var2"))'

But when I run it from a terminal (./myscript.sh), it ran with no error. Here's the code that gave the error:

#!/bin/bash

var1="A
B
C"
var2="1
2
3"
globalvar=0

while read v1 && read v2; do
    globalvar=$(echo $v1 $v2)
done<<<$(paste -d'\n' <(echo "$var1") <(echo "$var2"))

As commented below, it's probably some shell doesn't allow process substitution, thus why it failed. This command is running on iOS environment (jailbroken). Is there alternative way to implement this? Thanks in advance!

6
  • 1
    Not all shell implementations support process substitution. Commented Dec 7, 2019 at 13:10
  • No wonder! Any idea how to implement this in another way? Commented Dec 7, 2019 at 13:12
  • You don't specify how you run the script from shell. If you run e.g. bash script.sh, but your shebang points to /bin/sh, the invocation from the file browser will use a different shell. You should also provide a complete script that you can reproduce the issue with, not just a snippet that you suspect. Commented Dec 7, 2019 at 13:12
  • How could we have an idea without knowing what kind of a shell Filza provides? Commented Dec 7, 2019 at 13:34
  • Unfortunately that's a closed-source project and I couldn't find out what shell it's using too. Commented Dec 7, 2019 at 13:40

1 Answer 1

1

Try using 'here document' (<<) instead of 'here string' (<<<). It is supported by most shells.

while read v1 && read v2; do
    globalvar=$(echo $v1 $v2)
done <<__END__
$(paste -d'\n' <(echo "$var1") <(echo "$var2"))
__END__

The other option is create a shell wrapper that will force bash (from the question, looks like bash is installed and working). Rename original script to script-run, and modify the shell script to call the script-run

#! /bin/sh
exec /bin/bash ${0%/*}/script-run "$@"

Or other equivalent.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.