0

I tried to write a small ksh script:

fDestExists (){
    cd /tmp
    read vANSWER?" >> Do you want to create a repository in pwd ? Type YES or NO"
        echo "    |----> $(fGetDatum) You typed: " $vANSWER         
        if [ "$vANSWER" = "YES" ]; then
                read vANSWER2?" >> Type your repository's name."
                mkdir -p $vANSWER2
                cd $vANSWER2
                echo "    |----> Logs will be coped in pwd."        
        elif [ "$vANSWER" = "NO" ]; then
            echo "    |----> Logs will be coped in pwd."        
        else 
            echo "    |----> You typed a wrong answer; exiting."        
            exit 1
        fi  
    pwd #return
}

Several questions here.

  1. How can I use pwd's value in my echo?

  2. To return value, I read it was feasible using echo [yourValue] at last line. Then where you call the function, I guess I can use : $?. So how can I do the same behaviour with pwd?

1

1: you can directly use the PWD variable, eg:

echo "    |----> Logs will be coped in $PWD."

2: $? is used to retrieve the last command return value which is numerical. There is no way to pass a string here, the return value should be 0 meaning success or something different meaning some failure. Use return 0 or return -1 if you want to get that information. As you are modifying the script current directory, it will be available as $PWD in the caller side anyway.

  • Can I ask you one more question ? Is there any conventions about how writting script in KSH ? Like doing systematically "unset" to variables I use ? Or always using typeset to define new variables. – user1058398 Nov 18 '13 at 10:06
  • @user1058398 if the question is about details in this answer, you should just write them in a comment. Otherwise (or if you can word that request for details as a complete question) just put up a new question, possible refering to this one as background info. – Anthon Nov 18 '13 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.