tcsh:错误:$ ( ) 中的修饰符
tcsh: Bad : modifier in $ ( )
我想传递给我的 tcsh 脚本的最后一个参数。我注意到,通过回声测试,
echo ${*: -1:1}
returns 系列或参数中的最后一个参数。太棒了!
问题是,当我尝试将其放入 if 语句 或附加到它时,我收到 "Bad : modifier in $ ( )" 错误。这是为什么?
if ( -r ${*: -1:1}) then
echo "You have read permissions"
else
或者,同样的问题:
if ( ${*: -1:1}:e != tex) then
exit 2
endif
我试过 把
${*: -1:1}
在额外的括号中,但无济于事。我也尝试设置一个变量
set last = {*: -1:1}
然后在 if 语句中调用 $last,但这给了我一个 "Missing }" 错误。
想法?谢谢。
最终使用
set Y = `echo $* | awk -F " " '{print $NF}'`
代替我的最后一个参数,这与 tcsh 兼容。帮我解决了!
嗯,你回答了你自己的问题,但 tcsh
(和 csh
)也有一个方法:
set count=$#argv
echo "There are $count arguments"
set last="${argv[$#argv]}"
echo "The last argument is $last"
如果您想从 csh
中的 lists 中提取 words,只需确保使用大括号 {}
.
测试:
$ ./lastarg.csh 'a b' 'c d' 'e f'
There are 3 arguments
The last argument is e f
我想传递给我的 tcsh 脚本的最后一个参数。我注意到,通过回声测试,
echo ${*: -1:1}
returns 系列或参数中的最后一个参数。太棒了!
问题是,当我尝试将其放入 if 语句 或附加到它时,我收到 "Bad : modifier in $ ( )" 错误。这是为什么?
if ( -r ${*: -1:1}) then
echo "You have read permissions"
else
或者,同样的问题:
if ( ${*: -1:1}:e != tex) then
exit 2
endif
我试过 把
${*: -1:1}
在额外的括号中,但无济于事。我也尝试设置一个变量
set last = {*: -1:1}
然后在 if 语句中调用 $last,但这给了我一个 "Missing }" 错误。
想法?谢谢。
最终使用
set Y = `echo $* | awk -F " " '{print $NF}'`
代替我的最后一个参数,这与 tcsh 兼容。帮我解决了!
嗯,你回答了你自己的问题,但 tcsh
(和 csh
)也有一个方法:
set count=$#argv
echo "There are $count arguments"
set last="${argv[$#argv]}"
echo "The last argument is $last"
如果您想从 csh
中的 lists 中提取 words,只需确保使用大括号 {}
.
测试:
$ ./lastarg.csh 'a b' 'c d' 'e f'
There are 3 arguments
The last argument is e f