Explore tens of thousands of sets crafted by our community.
Bash Scripting Basics
41
Flashcards
0/41
'tar' command
Archives files into a tarball. Example: tar cvf archive.tar files/
until loop
Executes a block of code until the condition becomes true. Example: until [ count; ((count++)); done
for loop
Executes a block of code a set number of times. Example: for i in {1..5}; do echo
arithmetic expansion
Evaluates an arithmetic expression. Example: result=
chmod
Changes the file mode (permissions). Example: chmod 755 script.sh
'sort' command
Sorts lines of text files. Example: sort names.txt
shebang (#!)
Specifies the interpreter for a script. Example: #!/bin/bash
while loop
Executes a block of code as long as the condition is true. Example: while [ count; ((count++)); done
script arguments
Accesses arguments passed to a script. Example: echo 'First arg: 2'
command substitution
Captures the output of a command for use in another command or variable. Example: output=
select construct
Generates a simple menu from a list of items. Example: select item in list; do echo
getopts
Parses options and arguments passed to the script. Example: while getopts 'ab:c' flag; do case
'read' command
Reads a line from standard input. Example: read -p 'Enter your name: ' name
'grep' command
Searches for patterns within files using regular expressions. Example: grep 'Hello' file.txt
variable assignment
Assigns a value to a variable. Example: greeting='Hello, World!'
if statement
Executes a block of code if a certain condition is true. Example: if [ b ]; then echo 'Equal'; fi
function definition
Defines a reusable block of code. Example: function greet { echo 'Hello, 1'; }
'sed' command
Streams editor for filtering and transforming text. Example: sed 's/old/new/g' file.txt
nohup
Runs a command immune to hangups. Example: nohup ./long_running_task &
parameter expansion
Manipulates and retrieves information about variables. Example: echo
pushd and popd
Adds/removes directories to/from the directory stack. Example: pushd /tmp; popd
here document (heredoc)
Redirects input into an interactive shell script or program. Example: cat << 'EOF' > file.txt Hello, World! EOF
redirection
Redirects input/output from/to a file or command. Example: echo 'Hello' > file.txt
'uniq' command
Reports or omits repeated lines. Example: sort names.txt | uniq
conditional execution
Performs commands based on the success (exit status) of another. Example: make && echo 'Build succeeded' || echo 'Build failed'
'test' command
Evaluates conditional expressions. Example: test b && echo 'Equal'
background execution (&)
Runs a command in the background. Example: find / -name 'filename.txt' &
'find' command
Searches for files in a directory hierarchy. Example: find / -name 'filename.txt'
exit command
Terminates a script or a function with an optional exit status. Example: exit 0
'awk' command
Programming language for text processing. Example: awk '/pattern/ { print 0 }' file.txt
source command
Reads and executes commands from a file in the current shell session. Example: source ~/.bashrc
'wc' command
Prints the number of lines, words, and bytes in files. Example: wc -l file.txt
echo
Displays a line of text/string that is passed as an argument. Example: echo 'Hello, World!'
pipe
Pipes the output of one command as input to another. Example: cat file.txt | grep 'Hello'
variable reference
Retrieves the value of a variable. Example: echo
case statement
Executes code based on a pattern match. Example: case
'cut' command
Removes sections from each line of files. Example: cut -d':' -f1 /etc/passwd
process substitution
Treats the output or input of a process as a file. Example: diff <(ls dir1) <(ls dir2)
bracket expansion
Generates arbitrary strings. Example: mv file.{txt,pdf}
trap command
Catches and responds to signals and system events. Example: trap 'echo Signal detected' SIGINT
alias
Creates a shortcut for a command. Example: alias ll='ls -l'
© Hypatia.Tech. 2024 All rights reserved.