igauravsehrawat
igauravsehrawat

Reputation: 3954

What's difference between "$!" and "$?" in bash shell special parameters?

I know $? returns the last status code and also $!.

What is the exact difference of usage between the two.

Thanks

Edit : Dear Downvoters, I haven't removed this question since i want it to be indexed on Google, it's not easy to find documentation when searching on Google about this issue.

Sincerely

Upvotes: 0

Views: 68

Answers (1)

Samuel Toh
Samuel Toh

Reputation: 19298

They are different.

$! is the process identifier of the most recent background command and $? is like you said, the most recent foreground pipeline exit status.

Reference point : http://tiswww.case.edu/php/chet/bash/bashref.html#SEC28

Upvotes: 2

Related Questions