summaryrefslogtreecommitdiff
path: root/src/content/en/til/2020/11/12/useful-bashvars.adoc
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-04-30 06:23:27 -0300
committerEuAndreh <eu@euandre.org>2025-04-30 06:33:36 -0300
commit61ffa8466bbfa4ca8b13b442a3bd63ef9504a6da (patch)
treefc3c799bece509682b712f6e42e2816059c83c7a /src/content/en/til/2020/11/12/useful-bashvars.adoc
parentMakefile: No need to remove non-generated *.mo files (diff)
downloadeuandre.org-61ffa8466bbfa4ca8b13b442a3bd63ef9504a6da.tar.gz
euandre.org-61ffa8466bbfa4ca8b13b442a3bd63ef9504a6da.tar.xz
src/content/en/: Unpluralize collection names
Diffstat (limited to 'src/content/en/til/2020/11/12/useful-bashvars.adoc')
-rw-r--r--src/content/en/til/2020/11/12/useful-bashvars.adoc61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/content/en/til/2020/11/12/useful-bashvars.adoc b/src/content/en/til/2020/11/12/useful-bashvars.adoc
new file mode 100644
index 0000000..fb148fb
--- /dev/null
+++ b/src/content/en/til/2020/11/12/useful-bashvars.adoc
@@ -0,0 +1,61 @@
+= Useful Bash variables
+:categories: shell
+
+:bash: https://www.gnu.org/software/bash/
+:bash-bang-bang: https://www.gnu.org/software/bash/manual/bash.html#Event-Designators
+:bash-dollar-underscore: https://www.gnu.org/software/bash/manual/bash.html#Special-Parameters
+
+{bash}[GNU Bash] has a few two letter variables that may be useful when typing
+on the terminal.
+
+== `!!`: the text of the last command
+
+The {bash-bang-bang}[`!!` variable] refers to the previous command, and I find
+useful when following chains for symlinks:
+
+[source,sh]
+----
+$ which git
+/run/current-system/sw/bin/git
+$ readlink $(!!)
+readlink $(which git)
+/nix/store/5bgr1xpm4m0r72h9049jbbhagxdyrnyb-git-2.28.0/bin/git
+----
+
+It is also useful when you forget to prefix `sudo` to a command that requires
+it:
+
+[source,sh]
+----
+$ requires-sudo.sh
+requires-sudo.sh: Permission denied
+$ sudo !!
+sudo ./requires-sudo.sh
+# all good
+----
+
+Bash prints the command expansion before executing it, so it is better for you
+to follow along what it is doing.
+
+== `$_`: most recent parameter
+
+The {bash-dollar-underscore}[`$_` variable] will give you the most recent
+parameter you provided to a previous argument, which can save you typing
+sometimes:
+
+[source,sh]
+----
+# instead of...
+$ mkdir -p a/b/c/d/
+$ cd a/b/c/d/
+
+# ...you can:
+$ mkdir -p a/b/c/d/
+$ cd $_
+----
+
+== Conclusion
+
+I wouldn't use those in a script, as it would make the script terser to read, I
+find those useful shortcut that are handy when writing at the interactive
+terminal.