w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
echo - Syntax error: Bad substitution

The following line:

str=$(echo "${str// /-}")

is resulting into Syntax error: Bad substitution because you are not executing your script using bash. You are either executing your script using sh or dash which is causing the error.


EDIT: In order to fix your script to enable it to work with sh and dash in addition to bash, you could replace the following lines:

# get desired string
str=$(printf "%${leng}s" "-")

# replace empty spaces
str=$(echo "${str// /-}")

with

str=$(printf '=%.0s' $(seq $leng) | tr '=' '-')




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.