Bash expansions
In this post you will learn about bash expansions, you probably already used them if Clinica Stomatologie Bucuresti curs valutar crama lechinta Psiholog Cluj you have done something like “ls *.txt”. Basically the shell does some processing on the command line before actually executing it, which enables us to do a number of things.
Here is a small cheatsheet of the most useful expansions:
Brace expansion
List: {1,2,3}
![]()
This one can be useful to rename a file, for example you can rename access.log to access.log-old using this: mv access.log{,-old}
Range: {20..30}
![]()
Filename expansion (also know as globbing)
*.sh -> expands to all file names that have an extension of .sh
[st]* -> expands to all file names that start with either an 's' or a 't'
![]()
File expansion is very useful when you need to handle multiple files at the same time. If you need the full path as script input use find instead.
Tip: if you want to use a especial character without it being expanded you can enclose it in quotes, for example: echo ‘test*’
Variable expansion
echo $SHELL -> /usr/bin/zsh
echo $HOME -> /root
Tip: You can use the ‘env’ command to list all your environment variables. You may wanna pipe the output through less.
You can learn more here: http://www.gnu.org/software/bash/manual/html_node/Shell-Expansions.html