【问题标题】:How to execute .csh script with command line arguments from .csh script如何使用 .csh 脚本中的命令行参数执行 .csh 脚本
【发布时间】:2010-11-29 07:04:02
【问题描述】:

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

./shell_gen.csh test1 test2.prt

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

有人吗?

谢谢

生成.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

【问题讨论】:

  • 所以shell_gen.csh 回显“制作/scratch/graphics/gif”(即“/”和“gif”之间没有任何内容)?你的脚本对我有用(它与“制作/scratch/graphics/test1gif”相呼应)。

标签: shell scripting csh


【解决方案1】:

我会说,当位置参数变量与其他一些字符连接时,您可能需要在它们周围放置花括号:

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

但你可能也想要一个点:

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

引号防止空格。

【讨论】:

  • 那部分工作....当我从命令行运行脚本 ./shell_gen.csh test test1.prt 它工作正常...当它从上面的脚本调用时它不起作用
【解决方案2】:

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

您是否按照丹尼斯的建议尝试了 ${1}gif?我认为这应该可行。

尽管您的 generate 清楚地发送了第二个参数,但我在任何地方都没有看到对 $2 的引用。

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

最好的,
-pbr

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多