User Tools

Site Tools


linux:bash

This is an old revision of the document!


BASH

WILDCARD METACHARACTERS & EXPANSION

The shell expands special characters (globs/wildcards) before passing arguments to commands. This is called pathname expansion (or globbing).

Core wildcards:

  • * - zero or more characters. Example: ls *.jpg - all .jpg files in the current directory
  • ? - exactly one character. Example: cp report?.pdf /backup/ - report1.pdf, reportA.pdf, etc.

For example, following commands prints a list of files in the current directory:

$ echo *

HERE DOCUMENTS

Here document is just another form of I/O redirection where we embed a body of text into our script, the format is:

command << token
text
token

Example:

cat << _EOF_
hello
here
_EOF_

If we change the redirection operator from « to «- the sell will ignore leading tabs.

COMMAND SUBSTITUTION

Command substitution allows us to use the output of the command as expansion (substitution).

Basically it allows the output of the command to replace the command itself.

$ CURRENT_DATE=$(date)   # CURRENT_DATE will be assigned the output of date command

FILESYSTEM

stat file.txt            # shows additional details of the file (when created/modified etc)
linux/bash.1778677172.txt.gz · Last modified: by v1ctor