Logo
Pattern

Discover published sets by community

Explore tens of thousands of sets crafted by our community.

Bash Scripting Basics

41

Flashcards

0/41

Still learning
StarStarStarStar

'tar' command

StarStarStarStar

Archives files into a tarball. Example: tar cvf archive.tar files/

StarStarStarStar

until loop

StarStarStarStar

Executes a block of code until the condition becomes true. Example: until [ countge10];doechocount -ge 10 ]; do echo count; ((count++)); done

StarStarStarStar

for loop

StarStarStarStar

Executes a block of code a set number of times. Example: for i in {1..5}; do echo i;donei; done

StarStarStarStar

arithmetic expansion

StarStarStarStar

Evaluates an arithmetic expression. Example: result=((3+2))((3 + 2))

StarStarStarStar

chmod

StarStarStarStar

Changes the file mode (permissions). Example: chmod 755 script.sh

StarStarStarStar

'sort' command

StarStarStarStar

Sorts lines of text files. Example: sort names.txt

StarStarStarStar

shebang (#!)

StarStarStarStar

Specifies the interpreter for a script. Example: #!/bin/bash

StarStarStarStar

while loop

StarStarStarStar

Executes a block of code as long as the condition is true. Example: while [ countlt10];doechocount -lt 10 ]; do echo count; ((count++)); done

StarStarStarStar

script arguments

StarStarStarStar

Accesses arguments passed to a script. Example: echo 'First arg: 1,Secondarg:1, Second arg: 2'

StarStarStarStar

command substitution

StarStarStarStar

Captures the output of a command for use in another command or variable. Example: output=(lsl)(ls -l)

StarStarStarStar

select construct

StarStarStarStar

Generates a simple menu from a list of items. Example: select item in list; do echo item;doneitem; done

StarStarStarStar

getopts

StarStarStarStar

Parses options and arguments passed to the script. Example: while getopts 'ab:c' flag; do case flagina)echoawasused!;esac;doneflag in a) echo '-a was used!'; esac; done

StarStarStarStar

'read' command

StarStarStarStar

Reads a line from standard input. Example: read -p 'Enter your name: ' name

StarStarStarStar

'grep' command

StarStarStarStar

Searches for patterns within files using regular expressions. Example: grep 'Hello' file.txt

StarStarStarStar

variable assignment

StarStarStarStar

Assigns a value to a variable. Example: greeting='Hello, World!'

StarStarStarStar

if statement

StarStarStarStar

Executes a block of code if a certain condition is true. Example: if [ aeqa -eq b ]; then echo 'Equal'; fi

StarStarStarStar

function definition

StarStarStarStar

Defines a reusable block of code. Example: function greet { echo 'Hello, 1'; }

StarStarStarStar

'sed' command

StarStarStarStar

Streams editor for filtering and transforming text. Example: sed 's/old/new/g' file.txt

StarStarStarStar

nohup

StarStarStarStar

Runs a command immune to hangups. Example: nohup ./long_running_task &

StarStarStarStar

parameter expansion

StarStarStarStar

Manipulates and retrieves information about variables. Example: echo name:Default{name:-'Default'}

StarStarStarStar

pushd and popd

StarStarStarStar

Adds/removes directories to/from the directory stack. Example: pushd /tmp; popd

StarStarStarStar

here document (heredoc)

StarStarStarStar

Redirects input into an interactive shell script or program. Example: cat << 'EOF' > file.txt Hello, World! EOF

StarStarStarStar

redirection

StarStarStarStar

Redirects input/output from/to a file or command. Example: echo 'Hello' > file.txt

StarStarStarStar

'uniq' command

StarStarStarStar

Reports or omits repeated lines. Example: sort names.txt | uniq

StarStarStarStar

conditional execution

StarStarStarStar

Performs commands based on the success (exit status) of another. Example: make && echo 'Build succeeded' || echo 'Build failed'

StarStarStarStar

'test' command

StarStarStarStar

Evaluates conditional expressions. Example: test aeqa -eq b && echo 'Equal'

StarStarStarStar

background execution (&)

StarStarStarStar

Runs a command in the background. Example: find / -name 'filename.txt' &

StarStarStarStar

'find' command

StarStarStarStar

Searches for files in a directory hierarchy. Example: find / -name 'filename.txt'

StarStarStarStar

exit command

StarStarStarStar

Terminates a script or a function with an optional exit status. Example: exit 0

StarStarStarStar

'awk' command

StarStarStarStar

Programming language for text processing. Example: awk '/pattern/ { print 0 }' file.txt

StarStarStarStar

source command

StarStarStarStar

Reads and executes commands from a file in the current shell session. Example: source ~/.bashrc

StarStarStarStar

'wc' command

StarStarStarStar

Prints the number of lines, words, and bytes in files. Example: wc -l file.txt

StarStarStarStar

echo

StarStarStarStar

Displays a line of text/string that is passed as an argument. Example: echo 'Hello, World!'

StarStarStarStar

pipe

StarStarStarStar

Pipes the output of one command as input to another. Example: cat file.txt | grep 'Hello'

StarStarStarStar

variable reference

StarStarStarStar

Retrieves the value of a variable. Example: echo greetinggreeting

StarStarStarStar

case statement

StarStarStarStar

Executes code based on a pattern match. Example: case inputin[yY])echoYes;;[nN])echoNo;;)echoInvalid;esacinput in [yY]) echo 'Yes';; [nN]) echo 'No';; *) echo 'Invalid'; esac

StarStarStarStar

'cut' command

StarStarStarStar

Removes sections from each line of files. Example: cut -d':' -f1 /etc/passwd

StarStarStarStar

process substitution

StarStarStarStar

Treats the output or input of a process as a file. Example: diff <(ls dir1) <(ls dir2)

StarStarStarStar

bracket expansion

StarStarStarStar

Generates arbitrary strings. Example: mv file.{txt,pdf}

StarStarStarStar

trap command

StarStarStarStar

Catches and responds to signals and system events. Example: trap 'echo Signal detected' SIGINT

StarStarStarStar

alias

StarStarStarStar

Creates a shortcut for a command. Example: alias ll='ls -l'

Know
0
Still learning
Click to flip
Know
0
Logo

© Hypatia.Tech. 2024 All rights reserved.