Looking at the (prior) title, it has great chance to be marked as "duplicate".
I have a script (
test.sh) that does not take any arguments. I call it in following two ways :
bash "test.sh" # BASH_ARGC=() # BASH_ARGV=() bash -c "source test.sh" # BASH_ARGC=(="1" ="0") # BASH_ARGV=(="test.sh") # BASH_EXECUTION_STRING='source test.sh'
The only differences I found are those three bash variables. As test.sh does not take any arguments, I presume those differences are irrelevant.
Are there any other differences ?
Put another way, what (in
test.sh) can work in one calling method, but not in the other ?
@JdeBP, @Stephen Kitt
Thank you for answering, but my point is not about
detection of the differences, but about real differences that could affect an average programmer.
$0 being different is rarely "used" by an average programmer.