Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
bash shell脚本在比较文件大小后未能触发操作_Shell_Compare_Filesize - Fatal编程技术网

bash shell脚本在比较文件大小后未能触发操作

bash shell脚本在比较文件大小后未能触发操作,shell,compare,filesize,Shell,Compare,Filesize,在比较同一文件的文件大小时,嵌套if语句遇到问题 如果文件大小在x秒内没有更改,则执行文件扩展名从.tmp重命名为.pdf 我使用bash作为shell。让我感到不满的部分始于 if [ "$fsize1" -eq "$fsize2" ]; then 脚本似乎完全绕过了上面的部分。它甚至不进入嵌套的if语句(即调试echo语句“here”不会触发) 关于如何完成我想要的东西有什么想法吗?很可能是某个地方的语法问题。提前感谢您的投入 下面是我指的较大部分代码: if [ -f $TARGETDI

在比较同一文件的文件大小时,嵌套if语句遇到问题

如果文件大小在x秒内没有更改,则执行文件扩展名从.tmp重命名为.pdf

我使用bash作为shell。让我感到不满的部分始于

if [ "$fsize1" -eq "$fsize2" ]; then
脚本似乎完全绕过了上面的部分。它甚至不进入嵌套的if语句(即调试echo语句“here”不会触发)

关于如何完成我想要的东西有什么想法吗?很可能是某个地方的语法问题。提前感谢您的投入

下面是我指的较大部分代码:

if [ -f $TARGETDIR/*.tmp ]; then
  fsize=$(/usr/bin/ls -l | /usr/bin/grep *.tmp | /usr/bin/awk '{print $5}')
  fullfilename=$(/usr/bin/ls *.tmp)
  filenameonly=$(echo "$fullfilename" | sed 's/\.[^\.]*$//')
  fileextension=$(echo "$fullfilename" | sed 's/^.*\.//')
  echo $fullfilename
  echo $filenameonly
  echo $fileextension
  echo $fsize
  /usr/bin/sleep 5
  fsize2=$(/usr/bin/ls -l | /usr/bin/grep *.tmp | /usr/bin/awk '{print $5}')
  echo $fsize2
  if [ "$fsize1" -eq "$fsize2" ]; then
    /usr/bin/cat $TARGETDIR/$fullfilename > $TARGETDIR/$filenameonly.pdf
    echo "here"
    echo $fullfilename
    echo $filenameonly
    echo "file extension has been changed from tmp to pdf"
  fi
fi

那么fsize1不能等于fsize2。我注意到您的第二行代码创建了一个名为
fsize
的变量。
fsize1
在哪里创建?启用shell debugging以查看使用
set-vx
的变量使用了哪些值。祝你好运。
那么fsize1一定不能等于fsize2
(叹气)…有时候我不了解自己,伙计。。。