如何使用.csh脚本中的命令行参数执行.csh脚本

时间:2009-09-17 20:27:29

标签: shell scripting csh

所以我有.csh脚本generate.csh 我想从其中调用另一个.csh脚本。 我试过了

./ shell_gen.csh test1 test2.prt

但它运行shell_gen.csh但没有命令行参数。

任何?

由于

generate.csh

#!/bin/csh
./shell_gen.csh test1 test2.prt

shell_gen.csh

#!/bin/csh
set source = output
############################################################
# create pbm-gifs/ directory
############################################################
set destination1 = /scratch/graphics/$1gif
echo making $destination1

if ( ! -e $destination1 ) then
  mkdir $destination1
  foreach file ( $source/*.pgm )
    echo convert $file $destination1/$file:t:r.gif
    convert $file $destination1/$file:t:r.gif
end
else
echo "$destination1/ exists"
endif

2 个答案:

答案 0 :(得分:2)

我会说你可能需要在位置参数变量与其他一些字符连接时将花括号括起来:

set destination1 = /scratch/graphics/${1}gif

但你也可能想要一个点:

set destination1 = "/scratch/graphics/${1}.gif"

和引号可以防止空格。

答案 1 :(得分:1)

$ 1gif不是对位置参数的引用。

你有没有像丹尼斯建议的那样尝试$ {1} gif?我认为这应该有效。

虽然你的生成器明确发送了第二个参数,但我在任何地方都没有看到$ 2的引用。

最后第一行应该是#!/ bin / csh -f

最佳,
-pbr

相关问题