From 07c56086aa0c4e015c9044e333ae4001debcb28d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 30 Apr 2024 13:14:09 +0300 Subject: Update content for html --- gemfeed/2023-12-10-bash-golf-part-3.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'gemfeed/2023-12-10-bash-golf-part-3.html') diff --git a/gemfeed/2023-12-10-bash-golf-part-3.html b/gemfeed/2023-12-10-bash-golf-part-3.html index bd9b3521..021faf6f 100644 --- a/gemfeed/2023-12-10-bash-golf-part-3.html +++ b/gemfeed/2023-12-10-bash-golf-part-3.html @@ -8,7 +8,7 @@ -

Bash Golf Part 3


+

Bash Golf Part 3



Published at 2023-12-10T11:35:54+02:00

@@ -29,7 +29,7 @@ jgs^^^^^^^`^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2022-01-01 Bash Golf Part 2
2023-12-10 Bash Golf Part 3 (You are currently reading this)

-

FUNCNAME


+

FUNCNAME



FUNCNAME is an array you are looking for a way to dynamically determine the name of the current function (which could be considered the callee in the context of its own execution), you can use the special variable FUNCNAME. This is an array variable that contains the names of all shell functions currently in the execution call stack. The element FUNCNAME[0] holds the name of the currently executing function, FUNCNAME[1] the name of the function that called that, and so on.

@@ -69,7 +69,7 @@ http://www.gnu.org/software/src-highlite --> INFO|20231210-082732|123002|at_home_friday_evening|One Peperoni Pizza, please
-

:(){ :|:& };:


+

:(){ :|:& };:



This one may be widely known already, but I am including it here as I found a cute image illustrating it. But to break :(){ :|:& };: down:

@@ -92,7 +92,7 @@ INFO|20231210- Bash fork bomb

-

Inner functions


+

Inner functions



Bash defines variables as it is interpreting the code. The same applies to function declarations. Let's consider this code:

@@ -161,7 +161,7 @@ Wintel inside! Wintel inside!
-

Exporting functions


+

Exporting functions



Have you ever wondered how to execute a shell function in parallel through xargs? The problem is that this won't work:

@@ -251,7 +251,7 @@ http://www.gnu.org/software/src-highlite -->
... because some_other_function isn't exported! You will also need to add an export -f some_other_function!

-

Dynamic variables with local


+

Dynamic variables with local



You may know that local is how to declare local variables in a function. Most don't know that those variables actually have dynamic scope. Let's consider the following example:

@@ -291,7 +291,7 @@ foo What happened? The variable foo (declared with local) is available in the function it was declared in and in all other functions down the call stack! We can even modify the value of foo, and the change will be visible up the call stack. It's not a global variable; on the last line, echo "$foo" echoes the global variable content.


-

if conditionals


+

if conditionals



Consider all variants here more or less equivalent:

@@ -342,7 +342,7 @@ ok4a ok4b
-

Multi-line comments


+

Multi-line comments



You all know how to comment. Put a # in front of it. You could use multiple single-line comments or abuse heredocs and redirect it to the : no-op command to emulate multi-line comments.

@@ -366,7 +366,7 @@ COMMENT
I will not demonstrate the execution of this script, as it won't print anything! It's obviously not the most pretty way of commenting on your code, but it could sometimes be handy!

-

Don't change it while it's executed


+

Don't change it while it's executed



Consider this script:

-- cgit v1.2.3