How do I port a shell script to Perl?

后端 未结 1 1849
北海茫月
北海茫月 2021-01-29 08:27

This is a shell script , How do I accomplish the same thing in Perl?

prfile=~/sqllib/db2profile

profile()
{
if [ -f $prfile ] && [ \"$prfile\" != \"\" ]         


        
相关标签:
1条回答
  • 2021-01-29 08:57

    If I understand your objectives, I don't think you can use perl to accomplish this because perl will be running as a child process and it can not change the environment of your shell (it's parent process). Maybe this would work for you (untested, off the cuff)?

    prfile=~/sqllib/db2profile
    if [ -s "$prfile" ] ; then
       . "$prfile"
    else
      while true ; do 
        read -p "Enter a valid Profile : " prfile
        if [ -s "$prfile" ] ; then
           . "$prfile"
           break;
        fi
      done
    fi
    
    0 讨论(0)
提交回复
热议问题