---
title: "shell中的$@和$*的区别"
author: "vivimusing"
date: "2009-06-03T11:28:53Z"
tags: []
slug: "shell"
draft: false
lastmod: "2009-06-03T11:28:53Z"
id: 400843
url: "https://vivimusing.iteye.com/blog/400843"
---

$@和$\*在shell中都表示所有命令行参数，在没用双引号的时候，它们2个是差不多的，但是，加了双引号，结果就不同了

 

假设命令行参数 $1是hello $2是world

 

for i in "$\*"

do echo $i

done

结果是

hello world

 

for i in "$＠"

do echo $i

done

结果是

hello

world

 

"$@"将命令行参数视为单独的字符串，而"$\*"则把命令行参数当成一个整体的字符串来处理。