如何在bash脚本中读取带有登录的\print参数

huangapple go评论117阅读模式
英文:

how to read\print args in bash script with a login

问题

给定一个名为 foo.sh 的 Bash 脚本,用于执行登录操作。

虽然 foo.sh 被调用时带有参数,但这些参数并没有被打印出来。
如何打印传递给 foo.sh 的参数?例如:

$ ./foo.sh arg1 arg2

我期望得到的输出是:

arg1 arg2
英文:

given a bash script named foo.sh that performs a login

#!/usr/bin/env bash -l

bar() {
 echo "$@"
}

bar "$@"

although foo.sh is invoked with arguments, the arguments are not being printed.
how to print the arguments that are passed to foo.sh? e.g.

$ ./foo.sh arg1 arg2

i would expect to get the output

arg1 arg2

答案1

得分: 2

If you have a recent /usr/bin/env which accepts the -S (--split-string) option :

#!/usr/bin/env -S bash -l

bar() {
 echo "$@"
}

bar "$@"
英文:

If you have a recent /usr/bin/env which accept -S (--split-string) option :

#!/usr/bin/env -S bash -l

bar() {
 echo "$@"
}

bar "$@"

huangapple
  • 本文由 发表于 2023年5月29日 17:22:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76356111.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定