sách gpt4 ai đã đi

shell - truyền tất cả các đối số từ một tập lệnh shell sang một tập lệnh shell khác

In lại 作者:行者123 更新时间:2023-12-02 17:41:29 38 4
mua khóa gpt4 Nike

我有一个 shell 脚本,我向其中传递了一些参数。Test1.sh -a 1 -b 2 -c“一二三”

在 Test1.sh 中,我按以下方式调用另一个 shell 脚本。Test2.sh $*

我想将所有参数传递给 Test2,这些参数已传递给 Test1,并且格式也相同(带双引号等)。然而传递给 Test2 的参数是Test2.sh -a 1 -b 2 -c 一二三这对我不起作用。有没有办法解决这个问题,以便我可以像传递给 Test1 一样传递参数。

谢谢扎比

1 Câu trả lời

你需要说:

Test2.sh "$@"

Tài liệu tham khảoSpecial Parameters :

@

Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" .... If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters, "$@"$@ expand to nothing (i.e., they are removed).

手册说:

"$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS variable.

这解释了您观察到的结果。

关于shell - 将一个 shell 脚本的所有参数传递给另一个 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18492443/

38 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com