shell java 参数_在bash shell脚本中传播所有参数

本文介绍了一个用于测试Shell脚本中$@与$*参数解析差异性的脚本案例。通过对比不同参数传递方式下变量的解释行为,展示了如何区分处理带有空格的参数。此测试有助于理解Shell脚本中参数传递的细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我意识到这已经得到了很好的解答,但这里是“$ @”$ @“$ *”和$ *之间的比较

测试脚本的内容:

# cat ./test.sh

#!/usr/bin/env bash

echo "================================="

echo "Quoted DOLLAR-AT"

for ARG in "$@"; do

echo $ARG

done

echo "================================="

echo "NOT Quoted DOLLAR-AT"

for ARG in $@; do

echo $ARG

done

echo "================================="

echo "Quoted DOLLAR-STAR"

for ARG in "$*"; do

echo $ARG

done

echo "================================="

echo "NOT Quoted DOLLAR-STAR"

for ARG in $*; do

echo $ARG

done

echo "================================="

现在,使用各种参数运行测试脚本:

# ./test.sh "arg with space one" "arg2" arg3

=================================

Quoted DOLLAR-AT

arg with space one

arg2

arg3

=================================

NOT Quoted DOLLAR-AT

arg

with

space

one

arg2

arg3

=================================

Quoted DOLLAR-STAR

arg with space one arg2 arg3

=================================

NOT Quoted DOLLAR-STAR

arg

with

space

one

arg2

arg3

=================================

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值