|  
 
 
al2文件插入到helloworld.py文件的的python2的后面,然后输出到文件combine.py。 可以用命令 awk '1;/python2/{while (getline < "al2")print}' helloworld.py > combine.py。 
但是,我把al2换成变量,怎么就出错了呢? 脚本addal2.sh #!/bin/bash 
set -e set -o xtrace 
TOPDIR=$(cd $(dirname "$0")&& pwd) file= $TOPDIR/helloworld.py temp= $TOPDIR/combine.py 
al2= $TOPDIR/al2 
awk '1;/python2/{while (getline < "$al2")print}' $file  > $temp 
set +o xtrace 
helloworld.py内容 #!/usr/bin/python2 
print "Hello,world!" name = raw_input("What is your name?") print "Hello, "+ name + "!" 
al2的内容 #Licensed to the Apache Software Foundation (ASF) under one #or more contributor license agreements.  See the NOTICE file #distributed with this work for additional information #regarding copyright ownership.  The ASF licenses this file #to you under the Apache License, Version 2.0 (the #"License"); you may not use this file except in compliance #with the License.  You may obtain a copy of the License at 
#  #Unless required by applicable law or agreed to in writing, #software distributed under the License is distributed on an #"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY #KIND, either express or implied.  See the License for the  #specific language governing permissions and limitations #under the License. 
xtrace output说明al2是空值,所以应该检查看你的al2赋值是如何做的 
这是我的的版本,楼主比较一下 
#!/bin/bash 
set -e set -o xtrace 
TOPDIR=$(cd $(dirname "$0")&& pwd) file="$TOPDIR/helloworld.py" temp="$TOPDIR/combine.py" 
al2="$TOPDIR/al2" 
awk "1;/python2/{while (getline < \"$al2\")print}" $file 
set +o xtrace 
$./addal2.sh +++ dirname ./addal2.sh ++ cd . ++ pwd + TOPDIR=/var/temp + file=/var/temp/helloworld.py + temp=/var/temp/combine.py + al2=/var/temp/al2 + awk '1;/python2/{while (getline < "/var/temp/al2")print}' /var/temp/helloworld.py #!/usr/bin/python2 #Licensed to the Apache Software Foundation (ASF) under one #or more contributor license agreements.  See the NOTICE file #distributed with this work for additional information #regarding copyright ownership.  The ASF licenses this file 
print "Hello,world!" name = raw_input("What is your name?") print "Hello, "+ name + "!" + set +o xtrace 
 |