ITPub博客

首页 > Linux操作系统 > Linux操作系统 > [20210913]bash shell $* and $@ 的区别.txt

[20210913]bash shell $* and $@ 的区别.txt

原创 Linux操作系统 作者:lfree 时间:2021-09-14 09:18:18 0 删除 编辑

[20210913]bash shell $* and $@ 的区别.txt

--//bash shell $* and $@ 都是输出bash shell的整个命令行参数的内容,两者还是有点区别的,通过例子说明:

$ cat disp_argv_params.sh
#!/bin/bash
# display all the parameters
#
echo
echo "Using the \$* method: $*"
echo "$*" | xargs -IQ echo Q

count=1
for param in "$*"
do
     echo "\$* Parameter #$count = $param"
     count=$[ $count + 1 ]
done

echo
echo "Using the \$@ method: $@"
echo "$@" | xargs -IQ echo Q

count=1
for param in "$@"
do
     echo "\$@ Parameter #$count = $param"
     count=$[ $count + 1 ]
done
echo

--//测试:
$ . disp_argv_params.sh 1111 2222 3333        4444

Using the $* method: 1111 2222 3333 4444
1111 2222 3333 4444
$* Parameter #1 = 1111 2222 3333 4444

Using the $@ method: 1111 2222 3333 4444
1111 2222 3333 4444
$@ Parameter #1 = 1111
$@ Parameter #2 = 2222
$@ Parameter #3 = 3333
$@ Parameter #4 = 4444
--//咋一看似乎感觉差不多,不过你仔细看for就明白了.

$ . disp_argv_params.sh 1111 2222 3333                 "  4444"

Using the $* method: 1111 2222 3333   4444
1111 2222 3333   4444
$* Parameter #1 = 1111 2222 3333   4444

Using the $@ method: 1111 2222 3333   4444
1111 2222 3333   4444
$@ Parameter #1 = 1111
$@ Parameter #2 = 2222
$@ Parameter #3 = 3333
$@ Parameter #4 =   4444

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-2791907/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7970755