# \[Script] strncmp

Aaron Liao, 2022

Write a strncmp-like fuction with shell script.

```shell
#!/bin/bash

function _strncmp
{
    local str1=${1}
    local str2=${2}
    local i=0

   while [ ${i} -lt ${#str2} ];
    do
        if [ "${str1:i:1}" != "${str2:i:1}" ]; then
            return 1;
        fi

       i=$(expr ${i} + 1)
    done

   return 0;
}

_strncmp "hello world" "hello"

if [ $? -eq 0 ]; then
        echo "matched"
else
        echo "mismatched"

fi
```


---

# 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://applezu.netdpi.net/linux-prog/script-strncmp.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.
