我想通过 apt 非交互式安装 Chef,但默认情况下,apt 安装会显示以下提示:

有没有办法在安装过程中跳过此步骤或将值传递给 apt install?我只使用chef-solo,所以实际上并不需要服务器组件,所以只需在此提示上按回车即可。
我的输出VBoxManage list vms如下所示:
"arch" {de1a1db2-86c5-43e7-a8de-a0031835f7a7}
"arch2" {92d8513c-f13e-41b5-97e2-2a6b17d47b67}
Run Code Online (Sandbox Code Playgroud)
我需要抓住的名字arch,并arch2和它们保存到一个变量。
我需要在bash脚本中添加一个路径,但它可能会被执行多次:
export PATH=${OPENSHIFT_HOMEDIR}/app-root/runtime/bin/:${PATH}
Run Code Online (Sandbox Code Playgroud)
我不想一遍又一遍地添加该路径。如果还没有,我如何添加它$PATH?
我看过包装脚本示例,简而言之如下:
#!/bin/bash
myprog=sleep
echo "This is the wrapper script, it will exec "$myprog""
exec "$myprog" "$@"
Run Code Online (Sandbox Code Playgroud)
如上所示,它们exec几乎立即用$myprog. 一个人可以在没有exec:
#!/bin/bash
myprog=sleep
echo "This is the wrapper script, it will exec "$myprog""
"$myprog" "$@"
Run Code Online (Sandbox Code Playgroud)
在最后一个示例中,启动了一个新的 bash 实例,然后$myprog作为 bash 实例的子进程启动。
第一种方法有什么好处?
for k in {0..49};
do
a=$(($((2*$k))+1));
echo $a;
done
Run Code Online (Sandbox Code Playgroud)
Hi, I need a simplified expression for the third line, maybe one that does not use command substitution.
如何在 Bash 中找到发生错误的行号?
我创建了以下带有行号的简单脚本来解释我们需要什么。该脚本将从中复制文件
cp $file1 $file2
cp $file3 $file4
Run Code Online (Sandbox Code Playgroud)
当其中一个cp命令失败时,该函数将以exit 1 退出。我们希望向函数添加还打印带有行号(例如,8 或 12)的错误的功能。
这可能吗?
1 #!/bin/bash
2
3
4 function in_case_fail {
5 [[ $1 -ne 0 ]] && echo "fail on $2" && exit 1
6 }
7
8 cp $file1 $file2
9 in_case_fail $? "cp $file1 $file2"
10
11
12 cp $file3 $file4
13 in_case_fail $? "cp $file3 $file4"
14
Run Code Online (Sandbox Code Playgroud) 我想尝试简单的脚本
flag=false
while !$flag
do
read x
if [ "$x" -eq "true" ]
then
flag=true
fi
echo "${x} : ${flag}"
done
Run Code Online (Sandbox Code Playgroud)
但是当我运行它时,如果我输入true,我会看到那个x="true"and flag="true",但循环并没有结束。脚本有什么问题?如何正确反转布尔变量?
如何在 bash 脚本中编写以下内容?
tmux # Start tmux session.
compass watch /path/to/project1/compass/ # Run the first process.
Ctrl + B, " # Split the pane.
compass watch /path/to/project2/compass/ # Run the second process.
Ctrl + B, D # Exit the session.
Run Code Online (Sandbox Code Playgroud) 我想要实现的是能够在我使用 Yakuake/Konsole 时自动记录我的终端会话到文件。
如果在我的会话开始时我这样做,很容易实现:
script -f /home/$USER/bin/shell_logs/$(date +"%d-%b-%y_%H-%M-%S")_shell.log
Run Code Online (Sandbox Code Playgroud)
但是我想在启动 Yakuake 或打开新标签时自动运行上述内容。
使用 .bashrc 不起作用,因为它会在“脚本”打开一个新会话时创建无限循环,而该会话又会读取 .bashrc 并启动另一个“脚本”等等。
所以大概我需要以某种方式编写 Yakuake/Konsole 脚本,以便在打开新选项卡时运行一次“脚本”。问题是如何?
我的任务是创建一个自动化的服务器强化脚本,他们需要的一件事是每个命令执行的所有输出的报告。我想将错误消息存储在一个字符串中并将其附加到一个文本文件中。
假设我运行了这个命令:
/sbin/modprobe -n -v hfsplus
Run Code Online (Sandbox Code Playgroud)
在我的机器上运行它的输出是:
FATAL: Module hfsplus not found
Run Code Online (Sandbox Code Playgroud)
如何将该错误消息存储在字符串中?任何帮助将不胜感激。谢谢!