# bash

If conditions

Ref: <https://www.tldp.org/LDP/abs/html/comparison-ops.html>

```
#!/bin/bash

a=4
b=5

#  Here "a" and "b" can be treated either as integers or strings.
#  There is some blurring between the arithmetic and string comparisons,
#+ since Bash variables are not strongly typed.

#  Bash permits integer operations and comparisons on variables
#+ whose value consists of all-integer characters.
#  Caution advised, however.

echo

if [ "$a" -ne "$b" ]
then
  echo "$a is not equal to $b"
  echo "(arithmetic comparison)"
fi

echo

if [ "$a" != "$b" ]
then
  echo "$a is not equal to $b."
  echo "(string comparison)"
  #     "4"  != "5"
  # ASCII 52 != ASCII 53
fi

# In this particular instance, both "-ne" and "!=" work.

echo

exit 0
```

## To replace a string pattern with empty string in a file

```
files contains the following strings
  pic_000_1549487577_generic_combo_0_crop_001.jpg   green    [good: 0.01,  green: 0.99]
  pic_000_1549487577_generic_combo_0_crop_002.jpg   green    [good: 0.0,  green: 1.0]
  pic_000_1549487577_generic_combo_0_crop_003.jpg   green    [good: 0.01,  green: 0.99]

To replace a string pattern with empty string in a file

%s/_crop[0-9]*//g

output:
  pic_000_1549487577_generic_combo_0.jpg   green    [good: 0.01,  green: 0.99]
  pic_000_1549487577_generic_combo_0.jpg   green    [good: 0.0,  green: 1.0]
  pic_000_1549487577_generic_combo_0.jpg   green    [good: 0.01,  green: 0.99]


To replace a string from where it matches till the end
%s/\[.*//g

output:
  pic_000_1549487577_generic_combo_0.jpg   green
  pic_000_1549487577_generic_combo_0.jpg   green
  pic_000_1549487577_generic_combo_0.jpg   green
```

## AWK

```
# awk using multiple delimiters.
example: space and ':'

awk -F'[ :]' '{print $6}' AIreport_classification_combo_labEq_notresized_argmax_count.txt
```


---

# 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://bhabs.gitbook.io/allsetup/bash.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.
