Fundamental related of a bash builtin command named “if”

ABOUT if

Conditionals have many forms. The most basic form is: if expression then statement where
'statement' is only executed if 'expression' evaluates to true. '21' evaluates to true.xs

TYPICAL SHELL EXPOSURE
[bash]
$if true; then echo "works" ; fi
works
$if false; then echo "works" ; fi
$
[/bash]

LINK
https://stackoverflow.com/questions/16034749/if-elif-else-statement-issues-in-bash
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-6.html

Fundamental of a bash builtin command named “unalias”

ABOUT unalias

Remove each name from the list of defined aliases.  If -a is supplied, all alias definitions
are removed.  The return  value  is true unless a supplied name is not a defined alias.

[bash]
$unalias
unalias: usage: unalias [-a] name [name …]
$echo $?
2
$unalias -a
$echo $?
0
$unalias pwd
bash: unalias: pwd: not found
$pwd
/home/jeffrin
$alias ls list
bash: alias: ls: not found
bash: alias: list: not found
$alias list ls
bash: alias: list: not found
bash: alias: ls: not found
$alias pwd pwf
bash: alias: pwd: not found
bash: alias: pwf: not found
$alias
$alias list="ls"
$unalias list
$echo $?
0
$list
bash: list: command not found
$

[/bash]

LINK
https://www.quora.com/What-is-the-alias-unalias-command-in-Unix

Simple example of a bash builtin command named “wait”

ABOUT wait

wait waits for the process identified by process ID pid (or the job specified by job ID jobid), and
reports its termination status. If an ID is not given, wait waits for all currently active child
processes, and the return status is zero. If the ID is a job specification, wait waits for all processes
in the job's pipeline.

A TYPICAL SHELL EXPOSURE
[bash]
$sleep 10 &
[1] 7122
$wait 7122
[1]+ Done sleep 10
$sleep 20 &
[1] 7125
$wait 7125
[1]+ Done sleep 20
$sleep 20 &
[1] 7128
$wait 7128
[1]+ Done sleep 20
$sleep 20 &
[1] 7135
$wait 7135
[1]+ Done sleep 20
$wait
$wait
$

[/bash]

LINK
https://www.computerhope.com/unix/uwait.htm

A look into the bash builtin command named “until”

ABOUT until

until command in Linux used to execute a set of commands as long as the final command in the ‘until’
Commands has an exit status which is not zero. It is mostly used where the user needs to execute a set of
commands until a condition is true.

A TYPICAL SHELL EXPOSURE
[bash]
$i=0 ; until ((i > 5)) ; do echo $i; ((i = $i +1)) ; done
0
1
2
3
4
5
$i=0 ; until ((i > 5)) ; do echo $i; ((i++)) ; done
0
1
2
3
4
5
$i=0 ; until ((i > 1)) ; do echo $i; ((i++)) ; done
0
1
$i=0 ; until ((i > 5)) ; do echo $?; ((i++)) ; done
1
1
1
1
1
1
$

[/bash]
LINKS
https://www.geeksforgeeks.org/until-command-in-linux-with-examples/
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_09_03.html

Sessions of bash builtin command named “times”

ABOUT times

Print the accumulated user and system times for the shell and for processes run from the shell

[bash]
$times
0m0.063s 0m0.024s
0m0.008s 0m0.012s
$times pin
0m0.064s 0m0.025s
0m0.008s 0m0.012s
$times ping
0m0.065s 0m0.025s
0m0.008s 0m0.012s
$times –help
times: times
Display process times.

Prints the accumulated user and system times for the shell and all of its
child processes.

Exit Status:
Always succeeds.
$

[/bash]
https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html

Fundamentals related to a bash builtin command named “test”

ABOUT test

test provides no output, but returns 0 for "true" (test successful) and 1 for "false" (test failed).

RELATED COMMAND LINE EXPOSURE
[bash]
$num=10; if (test $num -gt 5); then echo "yes"; else echo "no"; fi
yes
$num=1; if (test $num -gt 5); then echo "yes"; else echo "no"; fi
no
$num=5; if (test $num -gt 5); then echo "yes"; else echo "no"; fi
no
$

[/bash]
LINK
https://www.computerhope.com/unix/bash/test.htm

Fundamentals related to bash builtin command named “shift”

ABOUT shift

shift [n]

The  positional  parameters  from  n+1  ...  are renamed to $1 ....  Parameters represented by the
numbers $# down to $#-n+1 are unset.  n must be a non-negative number less than or equal to $#.  If n is
0, no parameters  are  changed. If  n  is not given, it is assumed to be 1.  If n is greater than $#, the
positional parameters are not changed.  The return status is greater than zero if n is greater than $# or
less than zero; otherwise 0.

[bash]
$cat posiwork
shift
echo $1
$./posiwork hello world
world
$./posiwork hello

$./posiwork hello world people
world
$emacs posiwork
$cat posiwork
shift 2
echo $1
$./posiwork hello world people
people
$

[/bash]
LINKS
https://askubuntu.com/questions/939620/what-does-mean-in-bash
https://www.computerhope.com/unix/bash/shift.htm

Understanding bash fundamentals and also about return command

ABOUT return

Causes  a  function to stop executing and return the value specified by n to its caller.  If n is
omitted, the return status is that of the last command executed in the function body.

TYPICAL COMMAND LINE EXPOSURE
[bash]
$cat learn
function e() {
echo hello
echo "10"
}

e
value=e
#echo $value

$bash ./learn
hello
10
$

[/bash]
[bash]
$cat learn
function e() {
echo hello
echo "10"
}

value=e
echo $value

$bash ./learn
e
$
[/bash]
[bash]
$cat learn
function e() {
echo hello
echo "10"
}

value=$(e)
echo $value

$bash ./learn
hello 10
$

[/bash]
[bash]
$cat learn
function e() {
echo hello
echo "10"
}

value=$(e)
#echo $value

$bash ./learn
$

[/bash]
[bash]
$cat learn
function e() {
echo hello
echo "10"
}

e
value=$(e)
#echo $value

$bash ./learn
hello
10
$
[/bash]
[bash]
$cat learn
function e() {
echo hello
echo 10
}

e
value=$(e)
#echo $value

$bash ./learn
hello
10
$

[/bash]
[bash]
$cat learn
function e() {
echo hello
return 10
}

e
value=$(e)
echo $value

$bash ./learn
hello
hello
$

[/bash]
[bash]
$cat learn
function e() {
echo hello
return 10
}

e
value=$(e)
echo $value
echo $?

$bash ./learn
hello
hello
0
$

[/bash]
[bash]
$cat learn
function e() {
echo hello
return 10
}

e
echo $?

$bash ./learn
hello
10
$

[/bash]
LINKS
https://ryanstutorials.net/bash-scripting-tutorial/bash-functions.php
https://stackoverflow.com/questions/4419952/difference-between-return-and-exit-in-bash-functions