Table of contents
  1. Variables
    1. Special Variables
      1. The name of the Bash script.
      2. The first 9 arguments to the Bash script. (As mentioned above.)
      3. How many arguments were passed to the Bash script.
      4. All the arguments supplied to the Bash script.
      5. The exit status of the most recently run process.
      6. The process ID of the current script.
      7. The username of the user running the script.
      8. The hostname of the machine the script is running on.
      9. The number of seconds since the script was started.
      10. Returns a different random number each time is it referred to.
      11. Returns the current line number in the Bash script.
    2. Use
      1. The first, second, etc command line arguments to the script.
      2. To set a value for a variable. Remember, no spaces on either side of =
      3. Double will do variable substitution, single will not.
      4. Save the output of a command into a variable
      5. Make the variable var1 available to child processes.
  2. Std In and Out
    1. use a string put int script that needs a user response
    2. use output from a script to set a variable




Variables

Special Variables

The name of the Bash script.

$0

The first 9 arguments to the Bash script. (As mentioned above.)

$1 - $9

How many arguments were passed to the Bash script.

$#

All the arguments supplied to the Bash script.

$@

The exit status of the most recently run process.

$?

The process ID of the current script.

$$

The username of the user running the script.

$USER

The hostname of the machine the script is running on.

$HOSTNAME

The number of seconds since the script was started.

$SECONDS

Returns a different random number each time is it referred to.

$RANDOM

Returns the current line number in the Bash script.

$LINENO

Use

The first, second, etc command line arguments to the script.

$1, $2, ...

To set a value for a variable. Remember, no spaces on either side of =

variable=value

Double will do variable substitution, single will not.

Quotes " '

Save the output of a command into a variable

variable=$( command )

Make the variable var1 available to child processes.

export var1

Std In and Out

use a string put int script that needs a user response

export GH_TOKEN=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;
act=$(gh auth status -t >>(tee -a) 2>&1 | sed -n 's/.*Token: //p');
if [ "$act" == *"$GH_TOKEN"* ](%22$act%22%20==%20*%22$GH_TOKEN%22*.md#)
then echo $GH_TOKEN | gh auth login --with-token;

use output from a script to set a variable

tee can be used to create a file from output

here i take the out put pipe that and error output

 2 >&1

File descriptor 1

is the standard output (stdout)

File descriptor 2

is the standard error (stderr)

2> redirects stderr to an (unspecified) file.

&1 redirects stderr to stdout