Shahzad Shahzad - 4 months ago 37
Bash Question

Bad substitution error in bash script

I have tried a lot but couldn't get the solution out of it. I have a simple script:

#! /bin/sh
o="12345"
a=o
b=${!a}
echo ${a}
echo ${b}


When executed like

$ . scp.sh


it produces the correct output with no errors, but when executed like:

$ ./scp.sh


it produces


./scp.sh: 4: ./scp.sh: Bad substitution


Any ideas why this is happening.




I was suggested to use bash mode and it works fine. But when I execute this same script through Python (changing the script header to bash), I am getting the same error.

I'm calling it from Python as:

import os
os.system(". ./scp.sh")

Answer

Try using:

#!/bin/bash

instead of

#! /bin/sh
Comments