Bash 将参数传递给 --init-file 脚本
Bash pass argument to --init-file script
我是 运行 一个使用 bash --init-file script.sh
的 shell 脚本,它运行一些命令,然后打开一个交互式会话。如何从运行初始 bash 命令的进程将参数传递给此 init 文件? bash --init-file 'script.sh arg'
无效。
有趣的是,如果脚本包含 echo "$# $*"
,像我上面那样传递参数会导致它不打印任何内容,而不传递参数会打印“0”。
创建一个包含以下内容的文件:
#!/bin/bash
script.sh arg
将该文件传递给 bash:bash --init-file thatfile
I'd like the arg to come from the command that runs bash with the
从命令行创建文件并传递它:
arg=""
cat >thatfile <<EOF
$(declare -p arg)
script.sh \"$arg\"
EOF
bash --init-file thatfile
您可能有兴趣研究什么是 bash 中的 进程替换 。
我是 运行 一个使用 bash --init-file script.sh
的 shell 脚本,它运行一些命令,然后打开一个交互式会话。如何从运行初始 bash 命令的进程将参数传递给此 init 文件? bash --init-file 'script.sh arg'
无效。
有趣的是,如果脚本包含 echo "$# $*"
,像我上面那样传递参数会导致它不打印任何内容,而不传递参数会打印“0”。
创建一个包含以下内容的文件:
#!/bin/bash
script.sh arg
将该文件传递给 bash:bash --init-file thatfile
I'd like the arg to come from the command that runs bash with the
从命令行创建文件并传递它:
arg=""
cat >thatfile <<EOF
$(declare -p arg)
script.sh \"$arg\"
EOF
bash --init-file thatfile
您可能有兴趣研究什么是 bash 中的 进程替换 。