Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sh return: can only `return' from a function or sourced script

return statement error:urn: can only `return' from a function or sourced script in shell script myscript.sh

#!/bin/bash
if [ $# -ne 2 ]
then
    echo "Incorrect Usage : Arguments mismatch."
    return 2
fi

mv $1 $2

return 0

When i try to run

sh myscript.sh

Incorrect Usage : Arguments mismatch.
myscript.sh.sh: line 5: return: can only `return' from a function or sourced script

how to fix that error ?

like image 886
karthi keyan Avatar asked Jun 20 '18 13:06

karthi keyan


1 Answers

I guess you mean

exit 2

and

exit 0

Also, have a second look at the syntax of test.

like image 147
PhilMasteG Avatar answered Oct 23 '22 11:10

PhilMasteG