linux - shell 输出文件的奇怪行为 ( Linux )

标签 linux bash shell

你知道为什么下面的 shell 脚本只生成名为“Loading_EMP.sql”而不是“Loading_1_EMP.sql”的输出文件吗?

#!/bin/bash

JOBID="1"
TABLE="EMP"

echo 'test'  > Loading_$JOBID_$TABLE.sql; 

# Output
Loading_EMP.sql

# Expected Output
Loading_1_EMP.sql

最佳答案

echo 'test'  > Loading_${JOBID}_${TABLE}.sql; 

应该做,或者更好

echo 'test'  > "Loading_${JOBID}_${TABLE}.sql" # to avoid word splitting

Loading_$JOBID_$TABLE 中,shell 将 $JOBID_ 视为单个变量,因为它未设置,所以它替换 $JOBID_没有任何结果 Loading_EMP.sql


[ answer ]必须为您阅读。

关于linux - shell 输出文件的奇怪行为 ( Linux ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38671740/

相关文章:

linux - 批处理复杂任务图的监控/恢复

linux - 如何正确添加前缀和后缀双引号?

linux - 用于在另一个目录中创建文件的 shell 重定向命令

ruby-on-rails - gem install syck -v '1.0.1' 不起作用

linux - docker-compose 无法将 veth(虚拟接口(interface))添加到网桥 docker0

macos - 在 Bash 脚本中正确回显变量

perl - 将 Unix `cal` 输出转换为 Latex 表代码 : one-liner solution?

linux - 在 shell 脚本中获取命令输出

android - 在 ext4 和 fat32 之间建立链接

shell - 如何在makefile中获取shell环境变量?