> For the complete documentation index, see [llms.txt](https://benhurott.gitbook.io/appsecben/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://benhurott.gitbook.io/appsecben/tools/bash-scripting.md).

# Bash Scripting

### Foreach in Cat File

```bash
# my_script.sh
cat deps.txt | while read line
do
   echo "$line"
done
```

### Output to cmd and file at the same time

```bash
# the command output will be displaied to the terminal
# and will be writen in the myfile.txt
my_comand | tee myfile.txt
```

### Check if command exists

```bash
command_exists () {
    if [[ $(command -v $1) ]]; then
        return 0
    fi

    return 1
}

if command_exists "MyCommandHere"; then
    echo "MyCommandHere exists"
fi


# real world sample

if command_exists "exa"; then
    alias ls="exa"
fi
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://benhurott.gitbook.io/appsecben/tools/bash-scripting.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.
