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=([0]="1" [1]="0")
# BASH_ARGV=([0]="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 ?
Update 1
@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.
exit
at all and you source it you will exit from your current shell session. – jesse_b Jan 24 '20 at 20:23sh somescript
andsh -c '. somescript'
. – JdeBP Jan 24 '20 at 20:56"$0"
will likely differ – A.B Jan 24 '20 at 21:03