Artificial intelligent assistant

Taking shell arguments and updating values I am learning shell scripting and I am wondering how I can take arguments and use them to update a value. For example, I want to accomplish the following: > Take two arguments. A filename that points to the balance, and a number that indicates the deposit amount. The script should increase the account balance by the deposit amount, and save the result. > > Take two arguments. A filename that points to the account balance, and a number that indicates the debit amount. The script should reduce the account balance by the debit amount, and save the result.

You can view variables that are handed over to your script like this:


#!/bin/bash
echo "First parameter: $1"
echo "Second parameter: $2"
echo "And so on...."

echo "Number of parameters: $#"


So for your exmaple the following code could be possible:

**Increase** : `./inc_script.sh /path/to/file 5`


#!/bin/bash

AMOUNT=$(cat $1)

echo $(($AMOUNT + $2)) > $1


**Decrease** : `./dec_script.sh /path/to/file 5`


#!/bin/bash

AMOUNT=$(cat $1)

echo $(($AMOUNT - $2)) > $1


With `$()` you can execute a command in a subshell. With the `$(())` notation you can calculate in bash.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 283123aabc4e6f7d3085c1d0048c4ad9