'I want to use this shell script and change it to using command line argument [duplicate]

using ubuntu terminal so it could be with command-lins arg. thank you.

echo "enter number"
read num
function prime
{
for((i=2; i<=num/2; i++))
do
  if [ $((num%i)) -eq 0 ]
  then
    echo "$num is not a prime number."
    exit
  fi
done
echo "$num is a prime number."
}
r=`prime $number`
echo "$r"


Solution 1:[1]

2nd line can look like this

num=$1

function should be define first before other code

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1