linux 将csh脚本转换为bash脚本[已关闭]

wlsrxk51  于 2022-12-18  发布在  Linux
关注(0)|答案(1)|浏览(158)

已关闭。此问题需要超过focused。当前不接受答案。
**想要改进此问题吗?**更新此问题,使其仅关注editing this post的一个问题。

4天前关闭。
Improve this question
有人能帮我把这个csh脚本转换成bash脚本吗?谢谢

set cnt = 1
set cntmax = 10
set prod_step = step5
set equi_prefix = filename
while ( ${cnt} <= ${cntmax} )
@ pcnt = ${cnt} - 1
set istep = ${prod_step}_${cnt}
set pstep = ${prod_step}_${pcnt}
if ( ${cnt} == 1 ) then
set pstep = ${equi_prefix}
#Runing a command#
else
#Running a commnd#
endif
#Runing a command#
@ cnt += 1
end

我不擅长写剧本:)谢谢

anauzrmj

anauzrmj1#

这是一个粗略的bash脚本的快速尝试-看一看https://linuxhint.com/csh-vs-bash-nix-shells/

cnt=1
cntmax=10
prod_step=step5
equi_prefix=filename

while [[ "$cnt" -le "$cntmax" ]]; do
    # set pcnt to 1 less than cnt
    pcnt=$(( cnt - 1 ))
    istep=${prod_step}_${cnt}
    pstep=${prod_step}_${pcnt}

    # debugging - show output at this stage
    echo "cnt: $cnt"
    echo "pcnt: $pcnt"
    echo "istep: $istep"
    echo "pstep: $pstep"

    if [[ "$cnt" -eq "1" ]]; then
        echo "some command running if cnt=1"
        pstep=${equi_prefix}
    else
        echo "some command running if cnt not 1"
    fi
    (( cnt += 1 ))
done

下面是输出:

cnt: 1
pcnt: 0
istep: step5_1
pstep: step5_0
some command running if cnt=1
cnt: 2
pcnt: 1
istep: step5_2
pstep: step5_1
some command running if cnt not 1
cnt: 3
pcnt: 2
istep: step5_3
pstep: step5_2
some command running if cnt not 1
cnt: 4
pcnt: 3
istep: step5_4
pstep: step5_3
some command running if cnt not 1
cnt: 5
pcnt: 4
istep: step5_5
pstep: step5_4
some command running if cnt not 1
cnt: 6
pcnt: 5
istep: step5_6
pstep: step5_5
some command running if cnt not 1
cnt: 7
pcnt: 6
istep: step5_7
pstep: step5_6
some command running if cnt not 1
cnt: 8
pcnt: 7
istep: step5_8
pstep: step5_7
some command running if cnt not 1
cnt: 9
pcnt: 8
istep: step5_9
pstep: step5_8
some command running if cnt not 1
cnt: 10
pcnt: 9
istep: step5_10
pstep: step5_9
some command running if cnt not 1

相关问题