我在Linux中使用bash脚本迁移数据库输出文件,我想知道如何在bash脚本中执行Linux命令时处理错误。
例如,通常情况下,当我想循环遍历目录中的文件时,我会这样写它
# list files and grep results for .sql extension
for FILE in `ls | grep ".sql"`
do
echo "found file: $FILE"
done
它工作得很好,因为grep如果有.sql扩展名或不返回任何内容,就会返回文件名。
我想知道如何使用返回结果或错误的Linux命令,例如
ls ./*.sql
,
我在Windows上交叉编译用于Linux的Golang程序,使用:
go build -o myprog.bin myprog.go
为此,我必须设置环境变量GOOS=linux。由于我还在为windows编译一些程序,当我完成交叉编译时,我必须重新设置GOOS=windows。所以我有一个批处理文件,如下所示:
set GOOS=linux
go build -o myprog.bin myprog.go
set GOOS=windows
如果我碰巧同时为每个Linux和Windows编译两个程序,windows程序可能会被编译为Linux。是否有方法将环境变量的范围限制在windows上
我目前正在构建一些docker图像。
我发现我使用的Linux发行版很难适应Docker的多阶段构建,直到我找到了Nix。
使用Nix,我可以在不同图像(COPY --from=source/image /nix/store /nix/store)之间复制文件,而不必担心冲突和破坏。
但是在运行nix-env -i curl命令后,我发现它安装了太多的东西。
warning: there are multiple derivations named 'curl-7.60.0'; using the first one
installing 'curl-7.60.0
我正在尝试安装linux-image-extra-*包(这是Docker的先决条件),遵循这里的说明。
sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
但我得到以下错误消息:
Reading package lists... Done
Building dependency tree
Reading state information... Done
linux-image-extra-3.19.0-32-generic is already the newest versi