Consider this example snippet:
copy=true
model="model"
if [ ${copy} = true ] ; then
model+="Copy"
fi
echo ${model}
I am on the following platform:
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic
Output using sh test.sh
:
test2.sh: 4: test2.sh: model+=Copy: not found ---> error
model
Output using ./test.sh
:
modelCopy
I am aware of some of the differences between running the bash script using sh
and ./
after reading links[1, 2]. Still, I would like to know what's wrong with the use of +=
operator when I use sh
, why it doesn't work. I am some use-cases where I need to run the file using sh
only, how can I rectify that not found
error?