Skip to main content
edited title
Link

How to run a bash script from a sh(dashbash) script?

Added examples
Source Link

I have a sh (shebang #!/bin/sh) script (sh.sh) which invokes a bash (shebang #!/bin/bash) sub-script:

. "some-path/bash.sh"

In the bash script I have a declaration of an associative array: declare -A properties, thus getting the error declare: not found.

It's obvious why declare isn't found as the parent script is a sh script and not bash.

Is there a way to force bash syntax?

Another way is to open a new shell, but it's problematic because the subscript's purpose is to define variables to be used in the parent script. Sub-shells shouldn't be messing with parent's variable.

Parent (sh.sh):

#!/bin/sh
. "some-path/bash.sh"

Child (bash.sh):

#!/bin/bash
declare -A properties

Usage I was trying:

./sh.sh

I have a sh (shebang #!/bin/sh) script (sh.sh) which invokes a bash (shebang #!/bin/bash) sub-script:

. "some-path/bash.sh"

In the bash script I have a declaration of an associative array: declare -A properties, thus getting the error declare: not found.

It's obvious why declare isn't found as the parent script is a sh script and not bash.

Is there a way to force bash syntax?

Another way is to open a new shell, but it's problematic because the subscript's purpose is to define variables to be used in the parent script. Sub-shells shouldn't be messing with parent's variable.

I have a sh (shebang #!/bin/sh) script (sh.sh) which invokes a bash (shebang #!/bin/bash) sub-script:

. "some-path/bash.sh"

In the bash script I have a declaration of an associative array: declare -A properties, thus getting the error declare: not found.

It's obvious why declare isn't found as the parent script is a sh script and not bash.

Is there a way to force bash syntax?

Another way is to open a new shell, but it's problematic because the subscript's purpose is to define variables to be used in the parent script. Sub-shells shouldn't be messing with parent's variable.

Parent (sh.sh):

#!/bin/sh
. "some-path/bash.sh"

Child (bash.sh):

#!/bin/bash
declare -A properties

Usage I was trying:

./sh.sh
added 10 characters in body
Source Link

I have a sh (shebang #!/bin/sh) script (sh.sh) which invokes a bash (shebang #!/bin/bash) sub-script:

. "some-path/bash.sh"

In the bash script I have a declaration of an associative array: declare -A properties, thus getting the error declare: not found.

It's obvious why declare isn't found as the parent script is a sh script and not bash.

Is there a way to force bash syntax?

Another way is to open a new shell, but it's problematic because the subscript's purpose is to define variables to be used in the parent script. Sub-shells shouldn't be messing with parent's variable.

I have a sh (shebang #!/bin/sh) script which invokes a bash (shebang #!/bin/bash) sub-script:

. "some-path/bash.sh"

In the bash script I have a declaration of an associative array: declare -A properties, thus getting the error declare: not found.

It's obvious why declare isn't found as the parent script is a sh script and not bash.

Is there a way to force bash syntax?

Another way is to open a new shell, but it's problematic because the subscript's purpose is to define variables to be used in the parent script. Sub-shells shouldn't be messing with parent's variable.

I have a sh (shebang #!/bin/sh) script (sh.sh) which invokes a bash (shebang #!/bin/bash) sub-script:

. "some-path/bash.sh"

In the bash script I have a declaration of an associative array: declare -A properties, thus getting the error declare: not found.

It's obvious why declare isn't found as the parent script is a sh script and not bash.

Is there a way to force bash syntax?

Another way is to open a new shell, but it's problematic because the subscript's purpose is to define variables to be used in the parent script. Sub-shells shouldn't be messing with parent's variable.

Source Link
Loading