我有一个shell脚本,其中我使用带/ w标志的sed命令来创建输出文件。当我尝试在脚本中使用该文件时,我找不到文件,但在脚本退出后,它将在目录中创建。
我可以使用脚本中创建的文件吗?我需要做些什么呢?
#!/usr/bin/bash
fileQual=Test_load
dataFile=$fileQual.dat
corruptDataFile=$fileQual.err
cp "${dataFile}" "${dataFile}".cpy
LANG=C sed -n '/[\x00-\x08\x80-\xFF\x0B-\x0C\x0E-\x1F\x21-\x2B\x2F\x3A-\x40\x5B-\x60\x7B\x7D-\x7F]/w '${corruptDataFile}' ' "${dataFile}".cpy
echo "file corruptDataFile = ${corruptDataFile}"
ls ${corruptDataFile}
function checkNattach()
{
local fname="$1"
local atch
if [ -f "$1" ];then
atch="-a ${fname} "
echo "${fname} exists"
else
echo "${fname} not found"
fi
#resFun=atch
# echo " in function checkNattach atch $atch "
# echo " in function checkNattach resFun $resFun "
echo $atch
}
TIME=`date +%F-%H%M%S` # time stamp to the backup file
FILENAME="Test-$TIME.zip" # defining the format of the file name while backing up
echo $FILENAME
zipincl=""
zipincl="${zipincl} $(checkNattach ${corruptDataFile})"
echo "**********zipincl ${zipincl} ${corruptDataFile} "
zip -9 $FILENAME $corruptDataFile $dataFile
输出
file corruptDataFile = Test_load.err
ls: Test_load.err: No such file or directory
Test-2016-06-29-204904.zip
**********zipincl Test_load.err not found Test_load.err
+ zip -9 Test-2016-06-29-204904.zip Test_load.err Test_load.dat
zip warning: name not matched: Test_load.err
脚本完成后,当我查看目录时,文件实际上就在那里。有没有办法在zip命令中使用它?
答案 0 :(得分:1)
LANG=C sed -n '/[\x00-\x08\x80-\xFF\x0B-\x0C\x0E-\x1F\x21-\x2B\x2F\x3A-\x40\x5B-\x60\x7B\x7D-\x7F]/w '${corruptDataFile}' ' "${dataFile}".cpy
从上方行删除'${corruptDataFile}'
后的空格。它在末尾创建了带空格的文件名。