bash
This demonstrates multiple methods to overwrite a file with a string in Bash, including process substitution, direct redirection, piping to cat
, and piping to tee
.
cat > output.out <(echo "#helloworld") echo "#helloworld" > output.out echo "#helloworld" | cat > output.out echo "#helloworld" | tee output.out >/dev/null
bash internalfile and stream operationsstream redirection and pipingfile output
bash
This script demonstrates various globbing patterns (wildcards) in Bash for file matching, including single character, multi-character, character ranges, exclusions, and combinations. It also highlights special cases for matching dotfiles.
# Create some sample files touch file1.txt file2.txt file3.txt filea.txt fileb.txt filec.txt filed.txt filee.txt filef.txt # Examples ls file?.txt # => file1.txt file2.txt file3.txt filea.txt fileb.txt filec.txt filed.txt filee.txt filef.txt ls file*.txt # => file1.txt file2.txt file3.txt filea.txt fileb.txt filec.txt filed.txt filee.txt filef.txt ls file[ab].txt # => filea.txt fileb.txt ls file[a-c].txt # => filea.txt fileb.txt filec.txt ls file[^ab].txt # => file1.txt file2.txt file3.txt filec.txt filed.txt filee.txt filef.txt ls {filea*,fileb*} # => filea.txt fileb.txt # Dotfile special case: filename expansion can match dotfiles, but only if the pattern explicitly includes the dot as a literal character. ## Will not expand to ~/.bashrc: wildcards and metacharacters will NOT expand to a dot in globbing. Setting the "dotglob" option turns this off. ls ~/[.]bashrc # => No such file or directory ls ~/?bashrc # => No such file or directory ls ~/.[b]ashrc # => ~/.bashrc ls ~/.ba?hrc # => ~/.bashrc ls ~/.bashr* # => ~/.bashrc # Clean up the created files rm file1.txt file2.txt file3.txt filea.txt fileb.txt filec.txt filed.txt filee.txt filef.txt
bash internalfile and stream operationspathname expansion and matchingglobbing (wildcards)