如何在linux ubuntu 10.04中编写批处理命令?

发布于 2024-12-29 18:45:33 字数 442 浏览 0 评论 0原文

我安装了一个名为 Gdal 的库,它运行某些 GIS 命令。

该命令针对单个文件运行

gdal_translate -a_srs EPSG:25832 INPUT_FILE OUTPUT_FILE

,但我想运行一个批处理命令来迭代所有 *.tif 文件,这样我就不必编写每个文件的名称(我有 1300 个文件!)

我在一个 .sh 文件...但它不起作用

#!/bin/bash

for FILE in *.tif
do
  BASE=$FILE .tif
  NEWFILE=test/${BASE}.tif
  gdal_translate -s_srs EPSG:25832 $FILE $NEWFILE
done

有人能告诉我如何做到这一点吗?

你的,

罗伯特

I have an installed library called Gdal which runs certain GIS commands.

This command runs for a single file

gdal_translate -a_srs EPSG:25832 INPUT_FILE OUTPUT_FILE

but I would like to run a batch command which iterates through all *.tif files so I don´t have to write the name of each one (i´ve got 1300 files!)

I tried this in a .sh file...but it didn´t work

#!/bin/bash

for FILE in *.tif
do
  BASE=$FILE .tif
  NEWFILE=test/${BASE}.tif
  gdal_translate -s_srs EPSG:25832 $FILE $NEWFILE
done

could anyone show me how to do this?

yours,

Robert

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

燃情 2025-01-05 18:45:33

$FILE 包含 .tif 扩展名。而且 BASE=$FILE .tif 也不会按照您的想法执行(它会在命令执行期间将 $BASE 设置为 $FILE 来执行 .tif)。

您还可以了解 -a_srs-s_srs 之间的区别。我不知道你的意图是什么。

我认为最终结果是您希望使用 test/$FILE 作为输出文件名。

#!/bin/bash

for FILE in *.tif; do
  gdal_translate -s_srs EPSG:25832 "$FILE" "test/$FILE"
done

(引号使其适用于包含空格的路径。将 fordo 放在同一行是节省空间的常见编写方式。)

$FILE includes the .tif extension. Also BASE=$FILE .tif doesn't do what you think (it executes .tif with $BASE set to $FILE for the duration of the command).

You also have the difference between -a_srs and -s_srs. I don't know which you intended.

The end result is, I think, that you want to use test/$FILE as the output filename.

#!/bin/bash

for FILE in *.tif; do
  gdal_translate -s_srs EPSG:25832 "$FILE" "test/$FILE"
done

(The quotes make it work with a path with spaces in it. Putting the for and do on the same line is a common way of writing it to save space.)

套路撩心 2025-01-05 18:45:33

您的 FILE 变量末尾已经有 .tif,因此您要再次附加 .tif。试试这个:

#!/bin/bash

for FILE in *.tif 
do 
  NEWFILE=test/${FILE}
  gdal_translate -s_srs EPSG:25832 $FILE $NEWFILE
done

Your FILE variable already has .tif on the end, so you are appending .tif again. Try this instead:

#!/bin/bash

for FILE in *.tif 
do 
  NEWFILE=test/${FILE}
  gdal_translate -s_srs EPSG:25832 $FILE $NEWFILE
done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文