Here is a simple example showing that using declare
in a script the script will not run, while sourcing the script will:
$ cat /tmp/new
#! /bin/sh
declare -i hello
$ chmod a+rwx /tmp/new
$ /tmp/new
/tmp/new: 3: declare: not found
$ source /tmp/new
$
I wonder why directly running the script doesn't work, while sourcing it does? How can I make the first one work? Thanks!