Shell Scripting Flashcards
What does a shell script contain?
!/bin/bash (beginning of shell script)
Comments (#)
Commands (echo,cp,grep,etc.)
Statements (if,while,for,etc.)
How can you run a shell script?
chmod a+x scriptfile
./scriptfile
What command can you utilize to create a break inside a script?
echo
Create a script where
a=Jovan
b=Linux Engineer
c=Technical Center
!/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”
Create a basic script to take input from a user.
!/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.
Create a script to see if this file exists under /etc/yum.repos.d/random.repo.
!/bin/bash
clear
if [ -e /etc/yum.repos.d/random.repo ]
then echo File does exist else echo File does not exist fi
What does option -eq mean?
Equal to for numbers
What does option == mean?
Equal to for letters
What does option -ne mean?
Not equal to
What does option !== mean?
Not equal to for letters
What does option -lt mean?
Less than
What does option -le mean?
Less than or equal to
What does option -gt mean?
Greater than
What does option -ge mean?
Greater than or equal to
What does file option -s mean?
file exists and is not empty