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
create an array FRUITS with apple green apple orange
FRUITS[0]=apple FRUITS[1]="green apple" FRUITS[2]=orange echo ${FRUITS[*]} or echo ${FRUITS[@]}
26
how to check length of the array
echo ${#FRUITS[@]}
27
make an array with multiple values in 1 cmd
FRUIT_BASKET=(kiwi "dragon fruit" pear)
28
make an array with specific index values
FRUIT_BASKET=([10]=kiwi [1]="dragon fruit" [3]=pear)
29
create 2 variables a and b and do a division using them
echo $(($a/$b))
30
create a sales report and chart using brace expansion having the year and month
echo sales_{report, chart}_${date +%Y%m}
31
how to check hostname
hostname
32
how to check hostname and date on the same line
hostname; date
33
write the hostname and date data to a fiel
(hostname; date) > file.txt
34
create a hello.sh file with a hello variable
\#!/bin/bash (specifies the shell to use to execute the script ) HELLO="hello" echo $HELLO
35
#!/bin/bash echo "What is your name?" read NAME echo "hello" $NAME what does this do
allows users to key in their name and will return hello karthik
36
Can you execute the script by "hello.sh" without specifying the path?
yes, Enter "PATH=:$PATH"and press enter an empty entry means current directory