英文:
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 "$@"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论