0

Command 1:

[root@vmc-centos network-scripts]# ls -ltr | grep -oh "\w*ifcfg-ens3\w*" | grep -oh "\w*ens3\w*" | sort --unique
ens32
ens33
ens34 

Command 2:

[root@vmc-centos network-scripts]# ip link show | grep -oh "\w*ens3\w*"
ens32
ens33

Command 3: Nothing but (diff <(Command 1) <(Command 2) | sed -n 2p) \ [root@vmc-centos network-scripts]# diff <(ls -ltr | grep -oh "\w*ifcfg-ens3\w*" | grep -oh "\w*ens3\w*" | sort --unique) <(ip link show | grep -oh "\w*ens3\w*") | sed -n 2p ens34

Copied above command: 3 in a shell script (rundiffer.sh) and execute it:

[root@vmc-centos tmp]# vi rundiffer.sh
   cd /etc/sysconfig/network-scripts/
   result=$(diff <(ls -ltr | grep -oh "\w*ifcfg-ens3\w*" | grep -oh "\w*ens3\w*" | sort -- 
   unique) <(ip link show | grep -oh "\w*ens3\w*") | sed -n 2p)
   echo $result 

[root@vmc-centos tmp]# sh rundiffer.sh

Error :

rundiffer.sh: command substitution: line 3: syntax error near unexpected token `('
rundiffer.sh: command substitution: line 3: `diff <(ls -ltr | grep -oh "\w*ifcfg-ens3\w*" | grep -oh "\w*ens3\w*" | sort --unique) <(ip link show | grep -oh "\w*ens3\w*") | sed -n 2p)' 

Anyone got similar error, got a fix for the same ?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Vijay Kumar R
  • 41
  • 1
  • 1
  • 4
  • 1
    You can't use `sh` to run a `bash` script. They're two different interpreters for two different languages; it's like trying to compile a C++ program with a C compiler. (bash has a sh mode just like g++ has a C mode, but in both cases some features are unavailable there). – Charles Duffy Jun 23 '22 at 14:32
  • You should use code blocks, please have a look at [editing help](https://stackoverflow.com/editing-help). – Benjamin W. Jun 23 '22 at 14:33
  • 2
    (this is also part of why giving shell scripts a `.sh` extension regardless of which interpreter they're built for is an extremely bad idea; ideally, scripts are executable and shouldn't have any extension at all, but using `.sh` for a _bash_ script is extra confusing). – Charles Duffy Jun 23 '22 at 14:35
  • 1
    BTW, [Parsing `ls` output is a bad idea in general](https://mywiki.wooledge.org/ParsingLs). Better to use shell globbing to match against filenames. – Charles Duffy Jun 23 '22 at 14:52

0 Answers0