3 篇文章带有标签 “if”

AI 模型打包发布

运行

  • 默认从 .env 中读取环境变量
docker-compose run --rm model_package_release
  • 指定环境变量文件
docker-compose --env-file .env-test run --rm model_package_release

通过导出 Shell 环境变量可以替代 .env 文件中定义的环境变量

export MODEL_NAME=TEST
docker-compose run --rm model_package_release

Linux Shell 实践

  • 执行时的所有信息都输出到文件(&>)
echo hello &> log.info
$ cat log.info 
hello
  • 创建一个文件并写入内容(> filename <<EOF)
cat > hello.sh << EOF
#!/bin/bash
echo hello
EOF
  • 整数四则运算(let)
let n=10-3+4/2
echo $n
9
  • 四种执行模式运行
$ vim test.sh
#!/bin/bash
echo $str
$ chmod u+x test.sh
$ bash test.sh 
$ ./test.sh 
$ source test.sh 
hello world
$ . test.sh 
hello world
  • 导出变量(export),父进程定义的变量子进程可见。
$ export str
$ bash test.sh 
hello world
$ source test.sh 
hello world
  • 移除变量(unset)
$ unset str
$ echo $str
  • $$ 当前进程ID
$ echo $$
26102
  • $0 当前进程名
$ echo $0
-bash
  • 显示所有数组元素
$ echo ${ips[@]}
10.0.0.1 10.0.0.2 10.0.0.3