Running on the command line:
tmp=$(cd /sys/class/net; echo !(lo))
echo $tmp
eth0
Is OK. But running in script:
#!/bin/bash
tmp=$(cd /sys/class/net; echo !(lo))
echo $tmp
Outputs the error:
./test.sh: command substitution: line 3: syntax error near unexpected token '('
./test.sh: command substitution: line 3: 'cd /sys/class/net: echo !(lo))'
What is happening here? Why does it work correctly in the bash shell, but not in script?