To pass arguments to a Bash script, you can include them after the script name when you run it. Here's how to do it:
-
Create a script (e.g.,
script.sh):#!/bin/bash echo "First argument: $1" echo "Second argument: $2" -
Make the script executable:
chmod +x script.sh -
Run the script with arguments:
./script.sh "Hello" "World"
In this example:
$1refers to the first argument ("Hello").$2refers to the second argument ("World").
You can pass as many arguments as you need, and they can be accessed using $3, $4, etc. The special variable $@ can be used to refer to all arguments.
If you have any further questions or need clarification, feel free to ask!
