Linux Environment Variables and Shell Scripting Flashcards

1
Q

how to display a list of all the env variables

A

printenv or env

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

what does echo $HOME do

A

The absolute path of the home directory

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

what does echo $PATH

A

The value of the command search path.

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

what does echo $PS1 RETURN

A

The value of the primary prompt.

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

what does echo $PS2 RETURN

A

The value of the secondary prompt

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

what does echo $PWD RETURN

A

The absolute path of the current work directory.

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

WHAT DOES echo $SHELL RETURN

A

The absolute path of the login shell.

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

WHAT DOES echo $USER RETURN

A

name of current user logged in

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

Two processes connected by a pipe run in ________

A

parallel

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

what does ls | wc mean

A

ls is the producer

wc is the consumer of this output

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

how to look for all txt files

A

ls | grep txt

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

how to count number of lines in linux

A

wc -l

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

how to count number of characters in linux

A

wc -m

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

how to count number of bytes in linux

A

wc -c

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

how to view contents of a file

A

cat filename

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

how to read input from key board and save to file

A

cat > filename

ctrl + d to stop

17
Q

how to sort data in file

A

sort < filename

18
Q

how to append output to a file

A

echo world&raquo_space; filename

19
Q

sort the file and save the output to another file

A

sort < data.txt > sortedData.txt

20
Q

what does output 116 mean when wc cmd is used

A

1 line
1 word
6 bytes

21
Q

what does cat hello.txt 1>data.bak 2>error.txt

A

if cat hello.txt has no error the output will be saved to data.bak

else it will be saved to error.txt

22
Q

how to quote meta characters

A

-using backslash (): echo \; hello
-using single quote (‘) echo ‘;hello’
-using double quote (“) echo “;hello”

23
Q

how to return “today’s date is 29 feb 2022”

A

echo “today’s date is $DATE”

or

echo “today’s date is DATE

24
Q

make a name variable equal to student

A

NAME=student

echo $NAME (for checking)

25
Q

create an array FRUITS with
apple
green apple
orange

A

FRUITS[0]=apple
FRUITS[1]=”green apple”
FRUITS[2]=orange

echo ${FRUITS[*]}
or
echo ${FRUITS[@]}

26
Q

how to check length of the array

A

echo ${#FRUITS[@]}

27
Q

make an array with multiple values in 1 cmd

A

FRUIT_BASKET=(kiwi “dragon fruit” pear)

28
Q

make an array with specific index values

A

FRUIT_BASKET=([10]=kiwi [1]=”dragon fruit” [3]=pear)

29
Q

create 2 variables a and b and do a division using them

A

echo $(($a/$b))

30
Q

create a sales report and chart using brace expansion having the year and month

A

echo sales_{report, chart}_${date +%Y%m}

31
Q

how to check hostname

A

hostname

32
Q

how to check hostname and date on the same line

A

hostname; date

33
Q

write the hostname and date data to a fiel

A

(hostname; date) > file.txt

34
Q

create a hello.sh file with a hello variable

A

#!/bin/bash (specifies the shell to use to execute the script )
HELLO=”hello”
echo $HELLO

35
Q

!/bin/bash

echo “What is your name?”
read NAME
echo “hello” $NAME

what does this do

A

allows users to key in their name and will return

hello karthik

36
Q

Can you execute the script by “hello.sh” without specifying the path?

A

yes, Enter “PATH=:$PATH”and press enter

an empty entry means current directory