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

About bash builtin command named “eval”

ABOUT eval

eval is a builtin command of the Bash shell. It concatenates its arguments into a single string, joining the arguments with spaces, then executes that string as a bash command. It's similar to running bash -c "string", but eval executes the command in the current shell environment rather than creating a child shell process.

TYPICAL SHELL SESSION RELATED
[bash]
$eval ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether 70:5a:0f:b9:d8:5c brd ff:ff:ff:ff:ff:ff
3: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 68:14:01:07:36:1f brd ff:ff:ff:ff:ff:ff
inet 192.168.1.5/24 brd 192.168.1.255 scope global dynamic noprefixroute wlp2s0
valid_lft 253560sec preferred_lft 253560sec
inet6 fe80::6324:f2f6:2c32:5ac8/64 scope link noprefixroute
valid_lft forever preferred_lft forever
$echo $?
0
$echo $eval

$eval pw d
bash: pw: command not found
$eval

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

A bash builtin command named “enable” to enable or disable a bash builtin command

[bash light=”true”]
$command
$echo $?
0
$enable -n command
$command
bash: command: command not found
$echo $?
127
$enable command
$command
$enable -n enable
$enable
bash: enable: command not found
$
[/bash]
RELATED SOURCE CODE EXPOSURE
[c light=”true”]
/* Enable/disable shell commands present in LIST. If list is not specified,
then print out a list of shell commands showing which are enabled and
which are disabled. */
int
enable_builtin (list)
WORD_LIST *list;
{
int result, flags;
int opt, filter;
#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
char *filename;
#endif

result = EXECUTION_SUCCESS;
flags = 0;

reset_internal_getopt ();
while ((opt = internal_getopt (list, "adnpsf:")) != -1)
{
switch (opt)
{
case ‘a’:
flags |= AFLAG;
break;
case ‘n’:
flags |= NFLAG;
break;
case ‘p’:
flags |= PFLAG;
break;
case ‘s’:
flags |= SFLAG;
break;
case ‘f’:
#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
flags |= FFLAG;
filename = list_optarg;
break;
#else
builtin_error (_("dynamic loading not available"));
return (EX_USAGE);
#endif
#if defined (HAVE_DLCLOSE)
case ‘d’:
flags |= DFLAG;
break;
#else
builtin_error (_("dynamic loading not available"));
return (EX_USAGE);
#endif /* HAVE_DLCLOSE */
CASE_HELPOPT;
default:
builtin_usage ();
return (EX_USAGE);
}
}

list = loptend;

#if defined (RESTRICTED_SHELL)
/* Restricted shells cannot load new builtins. */
if (restricted && (flags & (FFLAG|DFLAG)))
{
sh_restricted ((char *)NULL);
return (EXECUTION_FAILURE);
}
#endif

if (list == 0 || (flags & PFLAG))
{
filter = (flags & AFLAG) ? (ENABLED | DISABLED)
: (flags & NFLAG) ? DISABLED : ENABLED;

if (flags & SFLAG)
filter |= SPECIAL;

list_some_builtins (filter);
}
#if defined (HAVE_DLOPEN) && defined (HAVE_DLSYM)
else if (flags & FFLAG)
{
filter = (flags & NFLAG) ? DISABLED : ENABLED;
if (flags & SFLAG)
filter |= SPECIAL;

result = dyn_load_builtin (list, filter, filename);
#if defined (PROGRAMMABLE_COMPLETION)
set_itemlist_dirty (&it_builtins);
#endif
}
#endif
#if defined (HAVE_DLCLOSE)
else if (flags & DFLAG)
{
while (list)
{
opt = dyn_unload_builtin (list->word->word);
if (opt == EXECUTION_FAILURE)
result = EXECUTION_FAILURE;
list = list->next;
}
#if defined (PROGRAMMABLE_COMPLETION)
set_itemlist_dirty (&it_builtins);
#endif
}
#endif
else
{
while (list)
{
opt = enable_shell_command (list->word->word, flags & NFLAG);

if (opt == EXECUTION_FAILURE)
{
sh_notbuiltin (list->word->word);
result = EXECUTION_FAILURE;
}
list = list->next;
}
}
return (result);
}
[/c]
SOURCE CODE TAKEN FROM DEBIAN Bash SOURCE

Get the hang of dbus-monitor command from dbus debian package

[bash light=”true”]
$dbus-monitor –session –profile | tee dbus-monitor-profile.txt
#type timestamp serial sender destination path interface member
# in_reply_to
sig 1542567372.723960 2 org.freedesktop.DBus :1.3693 /org/freedesktop/DBus org.freedesktop.DBus NameAcquired
sig 1542567372.723980 4 org.freedesktop.DBus :1.3693 /org/freedesktop/DBus org.freedesktop.DBus NameLost
sig 1542567373.088315 5 org.freedesktop.DBus :1.3692 /org/freedesktop/DBus org.freedesktop.DBus NameLost
sig 1542567373.088350 3737 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
sig 1542567373.088364 6 org.freedesktop.DBus :1.3692 /org/freedesktop/DBus org.freedesktop.DBus NameLost
sig 1542567373.088377 7254 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
mc 1542567373.447784 1 :1.3694 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus Hello
mr 1542567373.447814 1 org.freedesktop.DBus :1.3694 1
sig 1542567373.447825 7255 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
sig 1542567373.447835 2 org.freedesktop.DBus :1.3694 /org/freedesktop/DBus org.freedesktop.DBus NameAcquired
mc 1542567373.451542 2 :1.3694 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567373.451576 3 org.freedesktop.DBus :1.3694 2
mc 1542567373.451733 3 :1.3694 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567373.451750 4 org.freedesktop.DBus :1.3694 3
mc 1542567373.452108 4 :1.3694 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567373.452125 5 org.freedesktop.DBus :1.3694 4
mc 1542567373.452328 5 :1.3694 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus StartServiceByName
mr 1542567373.452344 6 org.freedesktop.DBus :1.3694 5
mc 1542567373.453509 6 :1.3694 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus GetNameOwner
mr 1542567373.453527 7 org.freedesktop.DBus :1.3694 6
mc 1542567373.454872 7 :1.3694 :1.11 /org/gtk/vfs/mounttracker org.gtk.vfs.MountTracker ListMountableInfo
mr 1542567373.454893 3626 :1.11 :1.3694 7
mc 1542567373.456695 8 :1.3694 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus RemoveMatch
mr 1542567373.456713 8 org.freedesktop.DBus :1.3694 8
mc 1542567373.456905 9 :1.3694 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567373.456921 9 org.freedesktop.DBus :1.3694 9
mc 1542567373.459070 10 :1.3694 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus RequestName
sig 1542567373.459106 10 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
sig 1542567373.459122 11 org.freedesktop.DBus :1.3694 /org/freedesktop/DBus org.freedesktop.DBus NameAcquired
mr 1542567373.459136 12 org.freedesktop.DBus :1.3694 10
mc 1542567373.724274 11 :1.3694 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567373.724303 13 org.freedesktop.DBus :1.3694 11
sig 1542567376.348823 7 org.freedesktop.DBus :1.3694 /org/freedesktop/DBus org.freedesktop.DBus NameLost
sig 1542567376.348857 3738 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
sig 1542567376.348869 8 org.freedesktop.DBus :1.3694 /org/freedesktop/DBus org.freedesktop.DBus NameLost
sig 1542567376.348879 7256 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
mc 1542567376.694978 1 :1.3695 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus Hello
mr 1542567376.695006 1 org.freedesktop.DBus :1.3695 1
sig 1542567376.695017 7257 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
sig 1542567376.695027 2 org.freedesktop.DBus :1.3695 /org/freedesktop/DBus org.freedesktop.DBus NameAcquired
mc 1542567376.697336 2 :1.3695 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567376.697363 3 org.freedesktop.DBus :1.3695 2
mc 1542567376.698034 3 :1.3695 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus StartServiceByName
mr 1542567376.698087 4 org.freedesktop.DBus :1.3695 3
mc 1542567376.698483 4 :1.3695 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567376.698500 5 org.freedesktop.DBus :1.3695 4
mc 1542567376.698861 5 :1.3695 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567376.698877 6 org.freedesktop.DBus :1.3695 5
mc 1542567376.699476 6 :1.3695 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus GetNameOwner
mr 1542567376.699494 7 org.freedesktop.DBus :1.3695 6
mc 1542567376.700365 7 :1.3695 :1.11 /org/gtk/vfs/mounttracker org.gtk.vfs.MountTracker ListMountableInfo
mr 1542567376.701865 3627 :1.11 :1.3695 7
mc 1542567376.703862 8 :1.3695 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus RemoveMatch
mr 1542567376.703888 8 org.freedesktop.DBus :1.3695 8
mc 1542567376.704263 9 :1.3695 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567376.704280 9 org.freedesktop.DBus :1.3695 9
mc 1542567376.705640 10 :1.3695 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus RequestName
sig 1542567376.705667 10 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
sig 1542567376.705678 11 org.freedesktop.DBus :1.3695 /org/freedesktop/DBus org.freedesktop.DBus NameAcquired
mr 1542567376.705688 12 org.freedesktop.DBus :1.3695 10
mc 1542567376.936982 11 :1.3695 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567376.937010 13 org.freedesktop.DBus :1.3695 11
sig 1542567379.255115 9 org.freedesktop.DBus :1.3695 /org/freedesktop/DBus org.freedesktop.DBus NameLost
sig 1542567379.255151 3739 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
sig 1542567379.255163 10 org.freedesktop.DBus :1.3695 /org/freedesktop/DBus org.freedesktop.DBus NameLost
sig 1542567379.255173 7258 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
mc 1542567379.448196 1 :1.3696 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus Hello
mr 1542567379.448227 1 org.freedesktop.DBus :1.3696 1
sig 1542567379.448238 7259 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
sig 1542567379.448249 2 org.freedesktop.DBus :1.3696 /org/freedesktop/DBus org.freedesktop.DBus NameAcquired
mc 1542567379.465578 2 :1.3696 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567379.465614 3 org.freedesktop.DBus :1.3696 2
mc 1542567379.467392 3 :1.3696 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567379.467426 4 org.freedesktop.DBus :1.3696 3
mc 1542567379.468500 4 :1.3696 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567379.468525 5 org.freedesktop.DBus :1.3696 4
mc 1542567379.469053 5 :1.3696 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus StartServiceByName
mr 1542567379.469072 6 org.freedesktop.DBus :1.3696 5
mc 1542567379.471752 6 :1.3696 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus GetNameOwner
mr 1542567379.471791 7 org.freedesktop.DBus :1.3696 6
mc 1542567379.473297 7 :1.3696 :1.11 /org/gtk/vfs/mounttracker org.gtk.vfs.MountTracker ListMountableInfo
mr 1542567379.474350 3628 :1.11 :1.3696 7
mc 1542567379.477282 8 :1.3696 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus RemoveMatch
mr 1542567379.477321 8 org.freedesktop.DBus :1.3696 8
mc 1542567379.477781 9 :1.3696 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567379.477799 9 org.freedesktop.DBus :1.3696 9
mc 1542567379.478799 10 :1.3696 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus RequestName
sig 1542567379.478826 10 org.freedesktop.DBus <none> /org/freedesktop/DBus org.freedesktop.DBus NameOwnerChanged
sig 1542567379.478838 11 org.freedesktop.DBus :1.3696 /org/freedesktop/DBus org.freedesktop.DBus NameAcquired
mr 1542567379.478848 12 org.freedesktop.DBus :1.3696 10
mc 1542567379.739670 11 :1.3696 org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus AddMatch
mr 1542567379.739707 13 org.freedesktop.DBus :1.3696 11
[/bash]