Shell Scripting Flashcards

1
Q

What does a shell script contain?

A

!/bin/bash (beginning of shell script)

Comments (#)
Commands (echo,cp,grep,etc.)
Statements (if,while,for,etc.)

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

How can you run a shell script?

A

chmod a+x scriptfile
./scriptfile

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

What command can you utilize to create a break inside a script?

A

echo

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

Create a script where
a=Jovan
b=Linux Engineer
c=Technical Center

A

!/bin/bash

a=Jovan
b=Linux Engineer
c=Technical Center

echo “My first name is $a”
echo “My job is $b”
echo “My skills were acquired at a $c”

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

Create a basic script to take input from a user.

A

!/bin/bash

a=‘hostname’
echo Hello, my server name is $a
echo
echo What is your name?
read b
echo
echo Hello $b
echo
echo What school did you go to?
read c
echo
echo That’s cool! I heard $c is a good school.

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

Create a script to see if this file exists under /etc/yum.repos.d/random.repo.

A

!/bin/bash

clear
if [ -e /etc/yum.repos.d/random.repo ]

   then 
   echo File does exist
   else 
   echo File does not exist fi
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does option -eq mean?

A

Equal to for numbers

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

What does option == mean?

A

Equal to for letters

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

What does option -ne mean?

A

Not equal to

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

What does option !== mean?

A

Not equal to for letters

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

What does option -lt mean?

A

Less than

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

What does option -le mean?

A

Less than or equal to

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

What does option -gt mean?

A

Greater than

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

What does option -ge mean?

A

Greater than or equal to

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

What does file option -s mean?

A

file exists and is not empty

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

What does file option -f mean?

A

File exists and is not a directory

17
Q

What does file option -d mean?

A

Directory exists

18
Q

What does file option -w mean?

A

file is writable

19
Q

What does file option -x mean?

A

File is executable

20
Q

What file option does -r mean?

A

File is readable

21
Q

Create a loop script to list weekdays.

A

!/bin/bash

i=1
for days in Mon Tues Wed Thurs Fri
do
echo “Weekday $((1++)) : $days”
done