Bash Scripting Flashcards
what is relative path?
location from the current directory
what’s absolute path?
something like /bin/ping
-used in case the program is not specified in PATH
~
current user’s home directory
*
wildcard used for finding certain types of files
output
results of command in a bash shell
command > file.txt
create or overwrite
command»_space; file.txt
create or append
what are 2 types of output redirection
- to a file
2. to another command
what bash character sends output to another command?
(pipe)
what is a “oneliner” script?
chaining multiple commands to automate a task
what does this oneliner do?
file ‘ls /etc/*conf’ | sort > test.txt && cat test.txt | wc -l
- anything between ‘’ operator gets evaluated first
- for each file listed (ls), it is sorted and put into a text file called test.txt
- && means execute what’s after it if the previous commands were successful
- read the test.txt file and print out the number of lines (wc = word count -l = lines)
what extension does a bash script file have?
.sh
what is the first line of any bash script file?
!/bin/bash
after saving a bash file, what should you make sure of?
make sure the file is executable, change the permissions
how do you make a file executable?
chmod+x
how do you run a script in linux terminal?
./
what is they syntax for a bash conditional statement?
if ; then commands elif ; then commands else commands fi
What do these operators mean?
- eq
- ne
equal
not equal
What do these operators mean?
- lt
- le
less than
less than or equal to
What do these operators mean?
- gt
- ge
greater than
greater than or equal to
what does this for loop do? #!/bin/bash
for i in $( ls ); do
echo item: $i
done
print out every item in a current directory
what does this for loop do? #!/bin/bash
for i in ‘seq 1 10’;
do
echo $i
done
uses the ‘seq’ command to iterate over numbers
what is the ‘while’ loops useful for
iterating over items in a file
what does the script below do?
while[condition]; do ; ; done
basic syntax to iterate over times