Suppose I have in main.sh:$NAME=a stringif [ -f $HOME/install.sh ]    . $HOME/install.sh $NAMEfiand in install.sh:echo $1This is supposed to echo a string, but it echoes nothing. Why?
Passing a variable to a bash script when sourcing it in another bash script?
bash;source;function
Michael Mrozek covers most of the issues and his fixes will work since you are using Bash.  You may be interested in the fact that the ability to source a script with arguments is a bashism.  In sh or dash your main.sh will not echo anything because the arguments to the sourced script are ignored and $1 will refer to the argument to main.sh. When you source the script in sh, it is as if you just copy and pasted the text of the sourced script into the file from which it was sourced.  Consider the following (note, I've made the correction Michael recommended):$ bash ./test.shA String$ sh ./test.sh$ sh ./test.sh HELLO WORLDHELLO WORLD