如何在linux ubuntu 10.04中编写批处理命令?
我安装了一个名为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$FILE 包含
.tif
扩展名。而且BASE=$FILE .tif
也不会按照您的想法执行(它会在命令执行期间将 $BASE 设置为 $FILE 来执行.tif
)。您还可以了解
-a_srs
和-s_srs
之间的区别。我不知道你的意图是什么。我认为最终结果是您希望使用 test/$FILE 作为输出文件名。
(引号使其适用于包含空格的路径。将
for
和do
放在同一行是节省空间的常见编写方式。)$FILE includes the
.tif
extension. AlsoBASE=$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.(The quotes make it work with a path with spaces in it. Putting the
for
anddo
on the same line is a common way of writing it to save space.)您的 FILE 变量末尾已经有 .tif,因此您要再次附加 .tif。试试这个:
Your FILE variable already has .tif on the end, so you are appending .tif again. Try this instead: