Escolar Documentos
Profissional Documentos
Cultura Documentos
echo $[4*$VAR+17]
fi
( -eq : is used integer comparison (look below)
-lt : less than
-le : less than or equal
-gt : greater than
-ge : greater than or equal
-eq : equal )
echo * is named wildcard for file names, as
special character called asterisk. It gets all file
names existant.
Echo work???ce output: workspace
$ is used for constant substituion
= dont put whitespaces before and after =
var1 = how
var1are = hello
var2 = you
var3 = $ {var1} are $ var2 =${} is used for
parameter substitution.
Echo aaa{bb,9,eee}fff={} used for expansion
output : aaabbffff aaa9fffff aaaeeefffff
i ie yaplsa bile sadece 1 expansion varm
gibi gzkecek.
File = aaa.txt
{
read line1
read line2
} < $file
redirection, sending a file
inside of curly brackets.
Echo $line1
echo $line2
\documentclass[allpaper,11pt]{article}
\usepackage
\author{Ula Keskindikkl}
\title{Comp 217 lel}
\begin{document}
\maketitle
\tableofcontents
\section {bla bla}
...
\subsection{la la}
\begin{enumerate}
\item ...yaz \item yaz
\end{enumerate}
\end{document}
Special Things:
\begin {enumerate} sigma k=0 to 5 : k^2+1
\item yaz $$\sum{k=0}^{5} k^2+1 $$
\end {enumerate}
$ $ is called a mathematical node
$$ $$ makes it graphically nice.
Repository : GIT, CVS, SVN
Subversive:
[ ] (whtespace) are void for test
sudo apt-get update
if [ -e ooo.txt ]; then
sudo apt-get install subversion
echo Yes
svn version
else
svn mkdir -m Hello this is my first project
echo No
svn://repo.yasar/myproject username=student
fi
( [ ] nothing if your command returns nothing, svn checkout svnpath/myproject
username=student takes the file out on your
then it is false, otherwise it is true.
own computer.
[ ] [ ] true [ : ]
/s -/ myproject/
blankspace character )
svn status
var = or var =
svn add a a makes it ready to be send to sever
if [ $var ]; then
svn commit -m This is our first commit!
echo Yes
Yuppy!...
else
svn diff
echo No
svn commit -m / added a new line
fi
svn status - -show updates username=student
Larry Wall Shell Programming is a 1950a
Quiz Answers:
juke box...
[ -f checks if it is a usual file
1) ? : could not solve the problem.
[ -e checks if a file exists
2) #!/bin/bash
[ -a same but no longer used
diff -r file1 file2 > report.txt
Agenda:
1) tar c,x,f,v,j,t,z
3) [], [[]] str compars 3)#!/bin/bash
stat -c %a ege/ege.txt > accessrights.txt
2) ln
4) (()) Clike code and art cp
5) ssh into
6) scp intro
IFS=$\n
tar cvf c : stands for create
for i in cat accessrights.txt; do echo $i; done
v: successful
f: filename
chmod $i ege/ege.txt
ttt.tar name of the .tar file to be created
stat -c %a ege/ege.txt
ttt name of the folder to be archived.
4) #!/bin/bash
Example : tar cvf ttt.tar ttt
tar cvfz ttt.tar.gz ttt ( -z means compress GZIP , OPTION=STATUS COMMIT UPDATE DIFF
GUNZIP algorithm -really fast) EXIT
Bash Example 13:
select opt in $OPTION; do
var1 = hello
if [$opt = STATUS ]; then
var2 = mello
if [ $var1 == $var2 ]; then == : str cmps echo Status is modified.
[
]
done
^ install ssh service.
Sudo apt-get install ssh
BASIC COMMAND GUIDE
sudo apt-get install open-ssh-server
ls --- lists your files
sudo service ssh start
ls -l --- lists your files in 'long format',
fconfig learn ip(server)
ls -a --- lists all files,
ping ip
emacs filename --- is an editor that lets you
ssh compare@ip
logout
create and edit a file. See the emacs page.
mv filename1 filename2 --- moves a file (i.e.
scp filename username@ip:parh)client
gives it a different name, or moves it into a
scp username@ip path/filename
different directory (see below)
newname copies it with a new name
cp filename1 filename2 --- copies a file
svn://repo.yasar.edu.tr/comp217
student: 123456
rm filename --- removes a file. It is wise to use
user: 12345
the option rm -i, which will ask you for
sudo apt-get update LATEX from TeX 80 confirmation before actually deleting anything.
sudo apt-get install texlive texlive-science
books,articles,papers,reports.. diff filename1 filename2 --- compares files,
and shows where they differ
#file (latex cmpile) #file.dvi
ps pdf msword doc rtf text
wc filename --- tells you how many lines, words,
Latex Guide:
and characters there are in a file
ged hello.tex
chmod options filename --- lets you change the
\documentclass{article}
read, write, and execute permissions on your
\begin{document}
files. . For example, chmod o+r filename will
Hello World!
make the file readable for everyone, and chmod
\end{document}
o-r filename will make it unreadable for others
latex hello.tex compile latex file
again.
ls hell*
File Compression
evince hello.dvi run file (evince commond
gzip filename --- compresses files, so that they
used for executing dvi file)
take up much less space. There are other tools for
dvips hello.dvi convert dvi file to .ps file
evince hello.ps
this purpose, too (e.g. compress), but gzip
ps2pdf hello.ps -;> convert ps to pdf
usually gives the highest compression rate.
latex hello.tex && dvips hello.dvi && ps2pdf
Gunzip filename --- uncompresses files
hello.ps && evince hello.pdf makes
compressed by gzip.
everything in just one command
gzcat filename --- lets you look at a gzipped file
dvipdf hello.dvi convert dvi to pdf
% comment line in latex
without actually having to gunzip it (same as
Example1 :
gunzip -c). You can even print it directly, using
\documentclass[allpaper,11pt] {article}
gzcat filename | lpr
\usepackage[english] {babel}
lpr filename --- print. Use the -P option to
\usepackage[utf8]{inputenc} turkish chs
specify the printer name if you want to use a
\begin{document}
Hseyin Hl
printer other than your default printer. For
\end{document}
example, if you want to print double-sided, use
Example 2:
'lpr -Pvalkyr-d', or if you're at CSLI, you may
text
grep [A-E] sortedlines.txt >
Executable shell : $ chmod a+rx first.sh
foundfrom_a_to_b.txt
C Programming Commandables:
grep -o [A-E] sortedlines.txt | wc -l >>
#include <stdio.h>
foundfrom_a_to_b.txt
#include <stdlib.h>
Bash Line Reading: #!/bin/bash
int input(char *s,int length);
while IFS='' read -r line || [[ -n "$line" ]]; do
int main(){
mkdir -p "./repository/$line"
char *buffer;
done < "$1"
char cmdbuf[256];
terminalden arrken "./script.sh students.txt"
size_t bufsize = 0;
Bash Repo: #!/bin/bash
ssize_t characters
while read line
FILE *p;
do
p = fopen("students.txt", "r");
mkdir -p "./repository/$line"
system("mkdir repository");
done <students.txt
while((characters =
Bash Nested:#!/bin/bash
getline(&buffer,&bufsize,p)) != -1)
while IFS='' read -r line || [[ -n "$line" ]]; do
{strcpy(cmdbuf, "mkdir ./repository/");
while IFS='' read -r line2 || [[ -n "$line2" ]]; do
strcat(cmdbuf, buffer);
mkdir -p "./repository/$line/$line2"
strcat(cmdbuf, "/");
done < "$2"
system(cmdbuf);
done < "$1"
printf("%s were read.\n", cmdbuf)}
Bash useful txt manipulations:
return(0);}
#!/bin/bash
Lab 4 - Grep, Pipes and RedireBct
Task 1: From the first labwork, find the list of
linecount=`wc -l anthem.txt`
echo Number of Line: $linecount
students and write it to a file
-List the first and last 10 entries in the file and
#!/bin/bash
wordcount=`wc -w anthem.txt`
create a new file named "first and last"
-Create a new file from the list of students that
echo Number of words:$wordcount#!/bin/bash
charcount=`wc -m anthem.txt`
has the name "ahmet"
echo Number of characters:$charcount
-Merge these two files into one single file
e.g. finding the right file among many, figuring
out which is the right version of something, and
even doing serious corpus work. grep comes in
several varieties (grep, egrep, and fgrep) and
has a lot of very flexible options. Check out the
man pages if this sounds good to you.
#!/bin/bash
bytecount=`wc -c anthem.txt`
echo Numbe r of bytes:$bytecount
#!/bin/bash
echo "Now lines of anthem.txt will be sorted
according to alphabetical order."
cat anthem.txt|grep '.'|sort>sorted.txt
echo "Sorting completed. Output has been
created as a file named sorted.txt"
#!/bin/bash
echo "Now words of anthem.txt will be sorted
according to alphabetical order."
r ' ' '\n' < anthem.txt|sort -u > sortbyword.txt
echo "Sorting completed. Output has been
created as a file named sortbyword.txt"
#!/bin/bash
echo "Now characters of anthem.txt will be
sorted according to alphabetical order."
fold -w1 anthem.txt|sort -u > sortbycharacter.txt
echo "Sorting completed. Output has been
created as a file named sortbycharacter.txt"
svn checkout/co
svn add : adds a new file to system.
svn propset : svn propset svn:keywords "Date
LastChangedBy" /path/to/filename.xml
svn delete : deletes the file
svn status : shows current status
svn update/up : updates the situation / syncs
svn commit/ci : recursively sends changes 2srv
svn diff
svn move