Looks like no one added any tags here yet for you.
what does chsh do?
changes your login shell
Makefile definition
A GNU utility that determines which pieces of a large program need to be compiled or recompiled; issues commands to compile and link them in an automated fashion
Variables in a Makefile
PROG = textr
CC = g++
CPPFLAGS = -g –Wall –I/usr/class/cs193d/textrInc
LDFLAGS = -L/usr/class/cs193/lib –lCoolFns
OBJS = main.o blurb.o database.o
Targets in a Makefile
$(PROG) : $(OBJS)
$(CC) $(LDFLAGS) -o $(PROG) $(OBJS)
main.o :
$(CC) $(CPPFLAGS) -c main.cpp
blurb.o : blurb.h
$(CC) $(CPPFLAGS) -c blurb.cpp
database.o : database.h
$(CC) $(CPPFLAGS) -c database.cpp
clean:
rm -f core $(PROG) $(OBJS)
Pre-req in a Makefile
$(PROG) : $(OBJS)
$(CC) $(LDFLAGS) -o $(PROG) $(OBJS)
main.o :
$(CC) $(CPPFLAGS) -c main.cpp
blurb.o : blurb.h
$(CC) $(CPPFLAGS) -c blurb.cpp
database.o : database.h
$(CC) $(CPPFLAGS) -c database.cpp
clean:
rm -f core $(PROG) $(OBJS)
Rules in a Makefile
$(PROG) : $(OBJS)
$(CC) $(LDFLAGS) -o $(PROG) $(OBJS)
main.o :
$(CC) $(CPPFLAGS) -c main.cpp
blurb.o : blurb.h
$(CC) $(CPPFLAGS) -c blurb.cpp
database.o : database.h
$(CC) $(CPPFLAGS) -c database.cpp
clean:
rm -f core $(PROG) $(OBJS)
What would be in a textr in a makefile
included files and libraries
echo -n “Hello”
print “Hello” without a newline
echo -e “Hello\nWorld”
print “Hello”
“World”
$echo “Hi, \n this is a test.”
Hi, \n this is a test.
echo -e "Hello\aWorld"
will trigger an alert sound if enabled
echo -e "Hello\bWorld"
“HellWorld”
echo -e "Hello\cWorld"
“Hello”
echo -e "Hello\fWorld"
“Hello” followed by form feed
echo -e "Hello\rWorld"
“World”
echo -e "Hello\tWorld"
“Hello World”
echo -e "Hello\vWorld"
Hello
World
name="Fatima"
echo 'Hello, $name'
“Hello, $name”
what does set do
will see all shell variables and functions
unset
removes variables or function from the current shell enviorment
shell variable rules
must begin with a lowercase or uppercase letter and not a digit, no spaces on either side of the equal sign ex. age=32
PS1
set to the string used as your prompt sign
PS2
set to the prompt sign that is displayed whenever you press RETURN
CD
set to absolute pathname
SHELL
set to the full pathname of your login shell
TERM
sets your terminal type
TZ
sets the time zone that you are in
echo "Today is `date
`"
Today is Mon Oct 30 10:45:00 UTC 2024
what does ; do
allows multiple commands on the same line
(ls -C ; date ; pwd) > outfile
three commands in sequence, grouped together, with the output redirected to a file
what does & do
sends command to run in the background
pipe operator |
uses the output of one command as the input to another command
-n
number all output lines
-A
show all charcters inclufing non-printing charcters ex. ^I as tabs
-b
number only non-empty output lines
cut -c 1-5 data.txt
print the first 5 characters from each line
cut -d ',' -f 1,3 data.csv
print the first and third columsns using , as delimiter
echo “Hi, `sleep 10
` Thanks for waiting”
will print hi and the thanks for wiating after 10s
wc command
counting command takes file as an argument
wc -l example.txt
num example.txt
ps -a
displays the status of all the active process, not just users
ps -f
displays full list of information including the full command line
kill command
terminates process
tee command
ls _C | tee dir.list
displays the current directory file names and also saves the output in dir.list
grep command
search for a specified pattern in a file or list of files
grep UNIX myfile
finds the lines that contain the word UNIX in myfile
grep -e "apple" -e "banana" fruits.txt
apple
banana
grep -i "apple" fruits.txt
Apple; makes the search regardless of upper or lower
grep -l "apple" fruits.txt vegetables.txt
fruits.txt; the file that the word is in
grep -n "apple" fruits.txt
1:apple
grep -v "apple" fruits.txt
banana
cherry
words that are not apple
sort -b data.txt
will ignore leading blanks when sorting
sort -d data.txt
sort with dictionary order; upper and lower case matter, upper first
sort -f data.txt
will sort ignoring upper and lower case
sort -n numbers.txt
sort numbers in a file
sort data.txt -o sorted_data.txt
sort and save th output in data.txt
sort -r data.txt
sort in reverse order
what is shell script
a command language - interpreted not compiled
sh command
run a script
$0
contains the name of the script
$1, $2…
contains the first through x command line parameters
$#
conatins the number of command line parameters
$@
contains all command line parameters: $` $2…
$?
conatins the exit status of the last command
$*
contains all command line parameres
$$
conatins PID number of the executing process
what does the read command do
used to read a line of input from standard input; accept input from user
exit n
exit
echo $?
print exit status of the last executed command
num1 -eqnum2
is num1 equal to num2
num1 -nenum2
is num1 not equal to num2
num1 -gtnum2
is num1 greater than num2
num1 -genum2
is num1 greater than or equal to num2
num1 - ltnum2
is number1 less than num2
num1 -lenum2
is num1 less than or equal to num2
string1 = string2
does string1 match string2
string1 != string2
does string1 not match string2
-n string
does string conatin characters (nonzero length)
-z string
is string an empty string(zero length)
-r filename
does filename exist and is it readable
-w filename
does filename exist and is it writable
-s filename
does filname exist and does it have a nonzero length
-f filename
does filename exist, but is it not a directory file
-d filename
does filename exist and is it a directory file
${variable: -string}
the valua of variable if it is set and not empty; otherwise the valus of string
${variable: +string}
the value of string if variable is set and not empty; otherwise variable is set to the value of string
${variable: =string}
the value of variable is it is set and not empty; otherwise variable is set to the value of string
${variable: ?string}
the value of variable if it is set and not empty; otherwise print the value of string and exit
expr 10 \* 2
20
expr 10 \% 3
1
x=`expr $x + 1`
adds 1 to x
can you use expr and let interchangibly
yes
for format
for variable
in list-of-values
do
commands
last command
done
while format
while
do
commands
last command
done
until
until
do
commands
last
done
-similar to while but will continue executing as along as the condition is false
alias command
for shortening the names of frequently used commands or changing command names
history command
keeps a list of all the commands you enter during the session
how to restart the history
remove the .sh_history
history 104
start from the command number 104