Feature Group
bash internal (293)
bash
This enhances the Bash shell experience by customizing the cd
command to list directory contents and creating aliases for common commands with interactive or human-readable options.
function cd { builtin cd "$@" && ls } alias cp='cp --interactive' alias mv='mv --interactive' alias rm='rm --interactive' alias df='df -h' alias du='du -h'
bash internalshell configuration and customizationaliases and functions
bash
This demonstrates the difference between double and single quotes in Bash for variable expansion, emphasizing the importance of correct quoting practices.
echo "$variable" # => Some string echo '$variable' # => $variable # When you use a variable itself — assign it, export it, or else — you write # its name without $. If you want to use the variable's value, you should use $. # Note that ' (single quote) won't expand the variables! # You can write variable without surrounding quotes but it's not recommended.
bash internaldata manipulationsstring manipulation and expansionsvariable expansion
bash
This demonstrates substring extraction from a variable using parameter expansion.
length=7 echo "${variable:0:length}" # => Some st # This will return only the first 7 characters of the value echo "${variable: -5}" # => tring # This will return the last 5 characters (note the space before -5). # The space before minus is mandatory here.
bash internaldata manipulationsstring manipulation and expansionsparameter expansionstring slicing
bash
This demonstrates indirect variable expansion in Bash, where the value of a variable is used to access another variable's value dynamically.
other_variable="variable" echo ${!other_variable} # => Some string # This will expand the value of `other_variable`.
bash internaldata manipulationsother variable featuresindirect variable expansion
bash
This code reads the contents of file.txt
, stores them in a variable, and prints the contents with custom text before and after, using echo
with the -e
flag to interpret newline characters.
Contents=$(cat file.txt) # "\n" prints a new line character # "-e" to interpret the newline escape characters as escape characters echo -e "START OF FILE\n$Contents\nEND OF FILE" # => START OF FILE # => [contents of file.txt] # => END OF FILE
bash internalfile and stream operationsfile readingreading file contents