2.2.2 Important Syntax Flashcards

1
Q

How do you get the current date in BASH?

A

DATE=$(date +"%y-%m-%d")

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you write an if statement in bash?

A

if [ condition ]; then
# code
fi

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are some loops in Bash?

A

for, while, and until loops

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you write a for loop?

A
for i in 1 2 3 4 5 
do 
    echo "Iteration $i" 
done 
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you write a while loop

A
#!/bin/sh 
  
counter=1 
  
while [ $counter -le 5 ] 
do 
    echo "Counter: $counter" 
36 
 
    counter=$((counter + 1)) 
done 
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you write an until loop

A

Just an inifnite loops that only ends on exit command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly