$# $@ $?

https://coderwall.com/p/85jnpq/bash-built-in-variables

 

I found the $#, $@ & $? bash built-in variables very useful since I knew linux and today I would like to share their usage. I hope that you don't mind if you already know.

Example:

file:test.sh
#! /bin/sh
echo '$#' $#
echo '$@' $@
echo '$?' $?

*If you run the above script as*

> ./test.sh 1 2 3

You get output:
$#  3
$@  1 2 3
$?  0

*You passed 3 parameters to your script.*

$# = number of arguments. Answer is 3
$@ = what parameters were passed. Answer is 1 2 3
$? = was last command successful. Answer is 0 which means 'yes'
posted @ 2021-04-22 23:52  hh9515  阅读(63)  评论(0)    收藏  举报