linux shell编程时报:bad substitution错误的解决办法

:bad substitution错误

应该是某个变量名字打错,找不对应的值对替换,直接报错结果;
检索全文中替换的${}变量,改正即可。

示例:
我用Linux shell脚本输出一段文字生成一个R程序,报错:
/mnt/bai/yongxin/bin/ternary_16s.sh: line 1: # 説我第一行就有错,由于输出多行,内部出错,无法检查错误所在行;我最终使用了逐行/段落添加的方法,逐渐缩小错误范围,找到了报错行(原文有几百行,找了一百多行才找到,试了十几次)。其行是正文中一个变量多打一了个空格,如${height },应该为${height};下次注意,直接找变量就可以马上解决。

cat <otu_ternary.r

#############################################################
# Title: Didfferent abundance OTU -- Tenary plot
# Author: Yong-Xin Liu
# E-mail: [email protected]
# Date: 2017/6/21
# Update: 2017/6/21
# Description: Script to draw tenary plot
# Input File required in the blow list: 
# 需要DA_OTU计算各组间的差异OTU结果
# 1. "../doc/design.txt"  Design of experiment
# 2. "otu_table.txt" OTU table, better include taxonomy
# 3. "../doc/group_tern.txt" ternary list
# Group A/B/C lie in left, right and top of triangle
#############################################################
  pdf(file=paste("ter_",tern[1],tern[2],tern[3],".pdf", sep=""), height = ${height }, width = ${width})
  tern_e(per3lg[,1:3], prop=T, col=per3\$color, grid_color="black", labels_color="transparent", pch=19, main="Tenary Plot")
  dev.off()

END

你可能感兴趣的:(shell)