Bash Scripting Flashcards Preview

Linux+ (LXO-104) > Bash Scripting > Flashcards

Flashcards in Bash Scripting Deck (30):
1

What do you put at the beginning of bash scripts?

#!/bin/bash

2

Where should you place a script if you want it to be executable from anywhere?

/home/user/bin

3

What do you have to do to the script myscript before you can run it?

chmod u+x myscript

4

myvar = $1

Will assign the value of the first argument to myvar

5

$#

Refers to the total number of arguments

6

How to do a numerical comparison with an if statement in a bash script

if (( $var == 0 ))

7

What does an if block end with?

fi

8

if test -f file

Tests if $file is a file

9

if [ -f $file ]

Tests if $file is a file

10

if [ -z "$string" ]

Checks if $string is empty

11

if statement flag for greater than

-gt

12

if statement flag for less than

-lt

13

if statement flag for greater than or equal

-ge

14

if statement flag for less than or equal

-le

15

if statement flag for equal

-eq

16

if statement flag for not equal

-ne

17

if statement flag for testing if directory

-d

18

if statement flag for testing if symlink

-l

19

What does putting a command between ` ` do in a bash script?

Executes the command in a new shell then immediately closes the shell

20

Which brackets must you use in order to use regular expressions and && and stuff?

[[ ]]

21

if statement flag for &&

-a

22

if statement flag for ||

-o

23

for statement syntax

for a in b
do
blahblah
done

24

while statement syntax

while [some condition];
do
blahblah;
done

25

case statement syntax

case $var in
1) first
do this thing;;
2) second
do this other thing;;
*)
this is the default
esac

26

read -n2 var

will read in 2 characters and put them in var

27

read -t

If input is not given within a certain time frame the script will move on

28

if [ -x $file ]

If $file exists and is executable

29

seq 10

Will print 1 through 10 in sequential order

30

seq 1 5 20

Will print 1-20 in increments of 5