# Command Line Arguments

You can pass arguments to your shell script when you execute it. To pass an argument, you just need to write it right after the name of your script.

Another thing that you need to keep in mind is that $0 is used to reference the script itself.

* $? ---- Exit status of last run command, 0 means success and non-zero indicates failure.
* $0 ---- File name of our script
* $1..$n ---- Script arguements
* $# ----- number of args that our script was run with
* $? ---- Exit status of last run command, 0 means success and anything else indicates failure.

```bash
#!/bin/bash

# Print value
echo "Argument one is $1" 
echo "Argument two is $2" 
echo "Argument three is $3"

# $1 is first argument
# $2 is second argument
# $3 is third argument

```

Run Script like this

```bash
./hello.sh dog cat bird
```

### User Input

To read the Bash user input, we use the built-in Bash command called read. It takes input from the user and assigns it to the variable.<br>

```bash
read name
```

```bash
#!/bin/bash

# User input
read name
read -p “name” name >> same line input
read -sp “pass” passwd>> invisible input
# Print value
echo “$name”

```

#### Sample Script

```bash
#!/bin/bash
echo "Enter your Name:"
read Name
echo "Enter username and password"
read -p 'username: ' username
read -sp 'password: ' psw
```

### Comment

Comments are used to leave yourself notes through your code. To do that in Bash, you need to add the # symbol at the beginning of the line.

```bash
# Test commands
```

Bash also contains multiline Comments.

```bash
<<comment
 "Code" or "Comments"
comment
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devops-3.gitbook.io/devops/docs/module-3-bash-scripting/command-line-arguments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
