[英]How to use the install command with a heredoc
I'm trying to convert an install script to use the install
command rather than creating a file and running chmod +x
against it.我正在尝试将安装脚本转换为使用
install
命令,而不是创建文件并对其运行chmod +x
。 This is the script right now:这是现在的脚本:
#!/usr/bin/env bash
install_target=/usr/local/bin/my_prog
volatile_path=/this/path/could/change
cat << EOF > "$install_target"
#!/usr/bin/env bash
"$volatile_path/some_other_executable" "\$@"
EOF
chmod +x "$install_target"
What I'd prefer to do is something like:我更喜欢做的是:
#!/usr/bin/env bash
install_target=/usr/local/bin/my_prog
volatile_path=/this/path/could/change
install "$install_target" << EOF
#!/usr/bin/env bash
"$volatile_path/some_other_executable" "\$@"
EOF
What am I missing to make this work?我缺少什么来完成这项工作?
Based on the comments, and assuming you're using a BSD version of install (GNU install
has full help shown by install --help
whereas BSD only shows basic usage) I think this is what you want to be doing:根据评论,并假设您使用的是 BSD 版本的安装(GNU
install
有install --help
显示的完整帮助,而 BSD 仅显示基本用法)我认为这就是您想要做的:
#!/usr/bin/env bash
install_target=/usr/local/bin/my_prog
volatile_path=/this/path/could/change
temp_file=/tmp/$0.$$.$RANDOM
cat << EOF > "$temp_file"
#!/usr/bin/env bash
"$volatile_path/some_other_executable" "\$@"
EOF
install -bd "$temp_file" "$install_target"
rm -f "$temp_file"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.