There are times when a shell script needs to allow the user to set custom string values that may include variable content. fstr
makes use of named placeholders that can be included in a string and substituted with computed values at a later point in the script.
Video tutorial:
Version | Date | Description |
---|---|---|
0.1.1 | 2025-04-06 |
Substitute |
0.1.0 | 2025-04-06 |
Initial release. |
Essential dependencies come preinstalled on Debian Linux. Debian users may safely skip the essential dependencies section. Users of other systems have to make sure that these are installed.
Click to view
Name | Notes |
---|---|
Bash |
Developed and tested on version 5.2.15. May work with other versions, but the specified one is recommended. Homepage: https://www.gnu.org/software/bash/ |
GNU coreutils |
Homepage: https://www.gnu.org/software/coreutils/ |
GNU sed |
Homepage: https://www.gnu.org/software/sed/ |
Required dependencies must be installed in order for fstr
to work.
Name | Installation | Notes |
---|---|---|
Lua | sudo apt install lua5.4 |
Developed and tested on version 5.4. May work with other versions, but the specified one is recommended. Lua's executable may be called Homepage: https://www.lua.org/ |
-
Clone this repository to a directory of your choice (for example,
~/local/src
):mkdir -pv ~/local/src cd ~/local/src git clone https://github.com/linguisticmind/fstr.git
-
Symlink the shell wrapper to a directory on your
PATH
(for example,~/local/bin
):cd fstr ln -srv fstr ~/local/bin
How do I add a directory to
PATH
?-
Open your
~/.bashrc
file in a text editor and add the following line to end of the file:export PATH="$HOME/local/bin:$PATH"
-
Restart your terminal session.
-
-
Symlink the man page to a directory on your
MANPATH
(for example,~/local/share/man
):cd ~/local/src/fstr ln -srv man/man1/fstr.1 ~/local/share/man/man1
Note: The
man
directory must contain subdirectories for different manual sections (man1
,man2
etc.).How do I add a directory to
MANPATH
?-
Open your
~/.bashrc
file in a text editor and add the following line to end of the file:export MANPATH="$HOME/local/share/man:$MANPATH"
-
Restart your terminal session.
-
-
To upgrade to the most recent version of
fstr
, rungit pull
in the cloned repository:cd ~/local/src/fstr git pull
FSTR(1) General Commands Manual FSTR(1)
NAME
fstr - substitute placeholders in strings
SYNOPSIS
fstr <str> [<name> <replacement> ...]
DESCRIPTION
There are times when a shell script needs to allow the user to set cus‐
tom string values that may include variable content. fstr makes use of
named placeholders that can be included in a string and substituted
with computed values at a later point in the script.
<str> A string with placeholders.
The placeholder format is:
(1) %<name>
or
(2) %{<name>:-<fallback>:+<override>}
:-<fallback> and :+<override> are optional and may go in
any order.
<name> is a placeholder name to match a <name> defined via com‐
mand line arguments. It may consist of one or more alphanumeric
characters and underscores.
<fallback> and <override> are also strings with placeholders
just like <str>.
<fallback> is substituted if command line arguments do not de‐
fine <name> and its <replacement>.
<override> is substituted instead of <replacement> allowing to,
for instance, insert extra characters next to <replacement>.
In strings with placeholders (<str>, <fallback>, <override>),
'\', '%', '{', ':', and '}' are special characters. They can be
escaped with backslashes ('\') to represent their literal val‐
ues.
<name> A placeholder name. May consist of one or more alphanumeric
characters and underscores.
<replacement>
A placeholder replacement. This is a literal string — unlike
<str>, <fallback>, and <override> which are strings with place‐
holders.
FILES
fstr.lua
The main Lua script.
fstr A shell wrapper for 'fstr.lua'.
tools/generate-bash-function
Outputs a Bash function based on 'fstr.lua'.
AUTHOR
Alex Rogers <https://github.com/linguisticmind>
HOMEPAGE
<https://github.com/linguisticmind/fstr>
COPYRIGHT
Copyright © 2025 Alex Rogers. License GPLv3+: GNU GPL version 3 or
later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
FSTR 0.1.1 2025-04-06 FSTR(1)