Shell 传递参数

Shell 传递参数

含有空格的参数,只需要在参数传递的时候加双引号就可以。

#!/bin/bash

echo "---------------with double quote ---------------"

echo "$1"

echo "$2"

echo "$3"

my_procedure() {

echo "$1"

echo "$2"

echo "$3"

}

my_procedure "$@"

echo "---------------withtout double quote ---------------"

echo $1

echo $2

echo $3

my_procedure() {

echo $1

echo $2

echo $3

}

my_procedure "$@"

echo "---------------withtout double quote by passing arguments---------------"

my_procedure $@

输入:

./test.sh "a b" "c d" "e f"

输出结果为:

---------------with double quote ---------------

a b

c d e

f g

a b

c d e

f g

---------------withtout double quote ---------------

a b

c d e

f g

a b

c d e

f g

---------------withtout double quote by passing arguments ---------------

a

b

c

前两部分无论在函数内外,加不加引号都一样,但是在函数传递的时候要保证加引号。

lalala lalala

a1.***t@mlsy.eu

4年前 (2021-10-02)

相关推荐

华为5s总成
365亚洲体育投注

华为5s总成

📅 08-27 👁️ 2427
​Android抓包总结
365亚洲体育投注

​Android抓包总结

📅 09-05 👁️ 4932
dnf85级该去哪个图
beat365中国官方网站

dnf85级该去哪个图

📅 01-12 👁️ 8057