Wednesday, May 8, 2024
14
rated 0 times [  14] [ 0]  / answers: 1 / hits: 3206  / 3 Years ago, wed, october 6, 2021, 10:26:20

While executing the below command directly over the terminal, its working fine:


comm -2 -3 <(sort FileOne.txt) <(sort FileTwo.txt) > myFile.txt

But while trying to execute it via .sh file, its giving error: Syntax error: "(" unexpected


Here is my code:


#!/bin/bash
##this will return the unique lines from the first file.
comm -2 -3 <(sort FileOne.txt) <(sort FileTwo.txt) > myFile.txt

I run the script like this:


sh ./myfilename.sh

Please help me to solve it.


Thanks!


More From » command-line

 Answers
7

If needed, make the script executable first by running:


chmod +x myfilename.sh

Then, run the script like this:


./myfilename.sh

Or run it explicitly with bash like this:


bash myfilename.sh

(These first two commands are essentially the same, since you have the bash shebang #!/bin/bash at the beginning of your script.)


DO NOT run like this:


sh myfilename.sh

Because then you are running the script with Dash (sh) and not with Bash (since your script has Bash-specific syntax).


[#79] Friday, October 8, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
skipu

Total Points: 366
Total Questions: 114
Total Answers: 112

Location: Saudi Arabia
Member since Mon, Sep 5, 2022
2 Years ago
skipu questions
Sun, Dec 26, 21, 05:25, 2 Years ago
Sun, Oct 31, 21, 02:01, 3 Years ago
Tue, Feb 14, 23, 19:48, 1 Year ago
Tue, Feb 22, 22, 08:37, 2 Years ago
;