Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

function in shell script returning 0 only

lockdir="somedir"
testlock(){
    retval=""
    if mkdir "$lockdir"
    then # Directory did not exist, but it was created successfully
         echo >&2 "successfully acquired lock: $lockdir"
         retval="true"
    else
         echo >&2 "cannot acquire lock, giving up on $lockdir"
         retval="false"
    fi
    echo "$retval"
}

retval=$( testlock )
if [ "$retval" == "true" ]
then
     echo "directory not created"
else
     echo "directory already created"
fi
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #function #shell #script #returning
ADD COMMENT
Topic
Name
2+5 =