What does $1 represent in a bash script?

0439

In a Bash script, $1 represents the first positional parameter or argument passed to the script when it is executed. This allows you to access and use the value of the first argument within the script.

For example, if you have a script named example.sh:

#!/bin/bash
echo "The first argument is: $1"

When you run the script with an argument:

./example.sh Hello

The output will be:

The first argument is: Hello

You can use $1, $2, $3, etc., to access subsequent arguments, with $1 being the first, $2 the second, and so on.

0 Comments

no data
Be the first to share your comment!