Check if input matches string argument in a bash script

I need to check if a commandline argument matches the one in a bash script, here is my code.


# lets call this

myFunction() {
if [[ $2 == '--log' ]]; then
    echo "hello world" >> file.log
    echo "Unknown argument"


Sample input:

bash --log

But doesn't seem to write anything into file.log

1 answer

  • answered 2021-09-23 13:16 Hai Vu

    You will need to pass the script's arguments to myFunction:

    myFunction "$@"

    The "$@" means "all the arguments passed to this script."

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum