Shell 传递参数

🏷️ bet体育365官网正规 ⏱️ 2026-01-23 05:07:45 👨‍🔧 admin 👁️ 1185 ⚡ 914
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)

相关资讯

跨蹇的意思
365bet大陆网址

跨蹇的意思

📅 09-12 🔧 admin
嘴 书法字典
365bet大陆网址

嘴 书法字典

📅 07-17 🔧 admin